static func randomShape() -> Shape {
// Find out count of possible shapes
var maxValue = 0
while let _ = self.init(rawValue: ++maxValue) {}
// Generate random number from number of shapes
let randomNumber = Int(arc4random_uniform(UInt32(maxValue)))
// Create and return shape
let shape = self.init(rawValue: randomNumber)!
return shape
}
专注于while let _ = self.init(rawValue: ++maxValue) {}
如何让我的增量或Swift 3友好?
我等这++
已经从斯威夫特过时,但是我不知道我可以改变我的方法仍然起作用权的错误。
我试过的MaxValue + = 1,我得到的错误
'+=' produces '()', not the expected contextual result type 'Int'
你的帮助深表感谢!
是否当++是一个函数的参数内使用这项工作?它将不得不将增量拉到前一行。酷,如果它:-) – Fogmeister
好吧,我只是测试了这一点。当它自己在一行(如你的例子)时,Xcode会自动修复它。但是当它在函数调用中使用时(如OP),Xcode只会将其标记为错误,并且不提供自动修复。 – Fogmeister