/// 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,memory并value在这方面是什么意思?
我在操场上.我试图使用arc4random_uniformfunc,但我收到此错误:使用未解析的标识符'arc4random_uniform'
我可以使用另一个func吗?
我正在尝试使用swift中的playground创建自定义委托.但是,不通过回调调用doSomething方法.似乎委托?.doSomething()不会触发XYZ类doSomething方法.提前致谢!
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) 在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'喜欢快速的东西?
如何在swift操场上输入pi符号.选项+ p无法在我的MacBookPro键盘上运行......?在输入选项+ p时,它在编辑器中显示","(逗号).
当我在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) 我有一个我在Mac上构建的游乐场,但打算在iPad版本上使用它.我有一个UIViewController,它显示我的所有内容.在iPad操场上,此ViewController会自动调整大小到实时视图的区域.这就是我要的.虽然在计算机上,UIViewController(以编程方式创建)只占用iPhone 7的空间.我想在这里放置一个iPad大小的区域,这样我就可以更大规模地测试我的内容.我将如何做到这一点(例如:设置Xcode的默认大小,但保持在iPad上的行为).
谢谢,
将
此代码在以前版本的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 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'
我在项目中更改字体大小时遇到了麻烦,所以我做了一个游乐场.无论我在哪里放置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)