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 弃用的错误,但是我不知道如何更改我的方法以使其仍然正常运行。
我试过 MaxValue += 1 但我得到了错误
'+=' produces '()', not the expected contextual result type 'Int'
非常感谢您的帮助!
最佳答案
++value
基本上是先增加值,然后使用新值。
所以这个...
someFunc(++value)
和做...一样
value += 1
someFunc(value)
关于swift - 如何使我的增量或 Swift 3 友好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40653855/