第一个块生成一个通用的 Swift 编译错误(甚至不指向该行)
let screenDivision = size.width / 5;
var game1 = SKSpriteNode(color: .redColor(), size: CGSize(width: 2 * screenDivision, height: size.height));
第二个块工作正常。
let screenDivision = size.width / 5;
var a = CGSize(width: 2 * screenDivision, height: size.height)
var game1 = SKSpriteNode(color: .redColor(), size: a);
为什么?我不想再次遇到这个错误并且不记得我在哪里编写了这样的代码。
(我还需要向它传递一个变量,而不是常量?Wtf...[如果我更改 var a, to let a,我会收到编译错误])
如果包含,错误就会消失UIColor
在你的电话中redColor
:
let screenDivision = size.width / 5;
var game1 = SKSpriteNode(
color: UIColor.redColor(),
size: CGSize(width: 2 * screenDivision,
height: size.height)
)
我不知道能够省略类方法的类型名称。我只知道枚举案例是可能的。 Swift 编程指南mentions https://developer.apple.com/library/ios/documentation/swift/conceptual/Swift_Programming_Language/Enumerations.html#//apple_ref/doc/uid/TP40014097-CH12-XID_221具体来说,这可以通过枚举来实现,但在类型方法 https://developer.apple.com/library/ios/documentation/swift/conceptual/Swift_Programming_Language/Methods.html#//apple_ref/doc/uid/TP40014097-CH15-XID_363部分。
事实上,我对第二个版本的工作感到惊讶。目前,除非您引用枚举案例,否则我将始终包含类型名称。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)