标签: swift-playground

关于UnsafeMutablePointer的destroy()的术语

/// Destroy the object the pointer points to.
///
/// Precondition: the memory is initialized.
///
/// Postcondition: the value has been destroyed and the memory must
/// be initialized before being used again.
func destroy()
Run Code Online (Sandbox Code Playgroud)

什么条款object,memoryvalue在这方面是什么意思?

pointers ios swift swift-playground

2
推荐指数
1
解决办法
1338
查看次数

随机功能操场迅捷

我在操场上.我试图使用arc4random_uniformfunc,但我收到此错误:使用未解析的标识符'arc4random_uniform'

我可以使用另一个func吗?

swift xcode6 swift-playground

2
推荐指数
1
解决办法
3534
查看次数

为什么不调用iOS中的自定义委托

我正在尝试使用swift中的playground创建自定义委托.但是,不通过回调调用doSomething方法.似乎委托?.doSomething()不会触发XYZdoSomething方法.提前致谢!

import UIKit

@objc protocol RequestDelegate
{
    func doSomething();

      optional  func requestPrinting(item : String,id : Int)
}


class ABC
{
    var delegate : RequestDelegate?
     func executerequest() {

        delegate?.doSomething()
        println("ok delegate method will be calling")
    }
}   

class XYZ : RequestDelegate
{  
    init()
    {
        var a  = ABC()
        a.delegate = self
    }

     func doSomething() {
       println("this is the protocol method")
    }
}    

var a = ABC()
a.executerequest()
Run Code Online (Sandbox Code Playgroud)

delegates ios swift swift-playground

2
推荐指数
1
解决办法
3679
查看次数

是否有一个Swift等同于Python中的'Filter'函数?

在python中,使用'filter'函数从字符串/列表中删除不需要的项目非常简单,该函数可以与'lambda'函数一起使用.在python中,它很简单:

a = "hello 123 bye-bye !!£$%$%"
b = list(filter(lambda x: x.isalpha(), a))
c = "".join(b)
print(c) #Which would print "hellobyebye"
Run Code Online (Sandbox Code Playgroud)

有没有办法轻松地在swift中复制它,而不先转换为unicode,然后检查unicode值是否在一定范围内?还有,什么'lambda'喜欢快速的东西?

python unicode lambda swift swift-playground

2
推荐指数
1
解决办法
318
查看次数

如何在swift操场上输入pi符号.选项+ p无法在我的MacBookPro键盘上运行......?

如何在swift操场上输入pi符号.选项+ p无法在我的MacBookPro键盘上运行......?在输入选项+ p时,它在编辑器中显示","(逗号).

ios swift swift-playground xcode7

2
推荐指数
1
解决办法
1604
查看次数

swift3 playground无法获取路径的沙箱扩展

当我在Playground中创建一个ImageView时,它会显示"沙盒扩展"错误.

let url = URL(string: "http://www.objc.io/images/covers/16.jpg")!
let image = CIImage(contentsOf: url)!
let imageView = UIImageView(frame: image.extent)
imageView.image = UIImage(ciImage: image )
PlaygroundPage.current.liveView = imageView
Run Code Online (Sandbox Code Playgroud)

控制台消息:

2017-02-19 15:37:06.803 Chapter2[73915:885328] Failed to obtain sandbox extension for
path=/var/folders/3t/2tbk2tn96_v6_39rrjym3hsr0000gn/T/com.apple.dt.Xcode.pg/containers/
com.apple.dt.playground.stub.iOS_Simulator.Chapter2-8E7AB6A8-3EF4-47C0-BDA2-117817EA2934/Library/Caches/
com.apple.dt.playground.stub.iOS_Simulator.Chapter2-8E7AB6A8-3EF4-47C0-BDA2-117817EA2934. Errno:1
Run Code Online (Sandbox Code Playgroud)

ios swift-playground swift3

2
推荐指数
1
解决办法
2186
查看次数

Xcode Swift Playgrounds - 如何为ViewController制作默认大小

我有一个我在Mac上构建的游乐场,但打算在iPad版本上使用它.我有一个UIViewController,它显示我的所有内容.在iPad操场上,此ViewController会自动调整大小到实时视图的区域.这就是我要的.虽然在计算机上,UIViewController(以编程方式创建)只占用iPhone 7的空间.我想在这里放置一个iPad大小的区域,这样我就可以更大规模地测试我的内容.我将如何做到这一点(例如:设置Xcode的默认大小,但保持在iPad上的行为).

谢谢,

ios swift swift-playground

2
推荐指数
1
解决办法
879
查看次数

Xcode 8.3.2游乐场实时视图渲染不起作用

此代码在以前版本的Xcode中完美运行,但现在它没有显示任何内容.它只显示活动指示器显示"正在运行的项目"

import UIKit
import PlaygroundSupport

let container = UIView()
container.frame.size = CGSize(width: 215.0, height: 215.0)

var view = UIView()
view.frame.size = CGSize(width: 185.0, height: 185.0)
view.center = container.center
view.layer.cornerRadius = view.frame.size.height/2
view.backgroundColor = UIColor.white

container.addSubview(view)

let scaleAnimation = CABasicAnimation(keyPath: "transform.scale")
scaleAnimation.fromValue = CGFloat(0.6)
scaleAnimation.toValue = CGFloat(1.15)
scaleAnimation.timingFunction = CAMediaTimingFunction(name:    kCAMediaTimingFunctionEaseOut)
scaleAnimation.isRemovedOnCompletion = false

let opacityAnimation = CABasicAnimation(keyPath: "opacity")
opacityAnimation.fromValue = CGFloat(0.0)
opacityAnimation.toValue = CGFloat(0.1)
opacityAnimation.duration = 1
opacityAnimation.isRemovedOnCompletion = false
opacityAnimation.autoreverses = true;


let circleAnimations: CAAnimationGroup = CAAnimationGroup()
circleAnimations.duration = …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift swift-playground

2
推荐指数
1
解决办法
1281
查看次数

使用未声明的类型'日期'Xcode 9 Swift 4

这是我在xcode 9游乐场的代码

class Tutorial: Codable {
    let title: String
    let author: String
    let editor: String
    let type: String
    let publishDate: Date

    init(title: String, author: String, editor: String, type: String, publishDate: Date) {
        self.title = title
        self.author = author
        self.editor = editor
        self.type = type
        self.publishDate = publishDate
    }
}
Run Code Online (Sandbox Code Playgroud)

显示错误使用未声明类型'Date'

ios swift swift-playground

2
推荐指数
1
解决办法
3579
查看次数

Swift font.withSize不改变UILabel上的字体大小

我在项目中更改字体大小时遇到​​了麻烦,所以我做了一个游乐场.无论我在哪里放置font.withSize属性,模拟器都不会反映字体大小的变化.

import UIKit
import PlaygroundSupport

    class MyViewController : UIViewController {
        override func loadView() {
            let view = UIView()
            view.backgroundColor = .white

            let label = UILabel()
            label.font.withSize(80)
            label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
            label.text = "Hello Mom!"
            label.textColor = .black



            view.addSubview(label)
            self.view = view
        }
    }
Run Code Online (Sandbox Code Playgroud)

fonts font-size uilabel swift swift-playground

2
推荐指数
1
解决办法
2228
查看次数