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
}
Run Code Online (Sandbox Code Playgroud)
专注于 while let _ = self.init(rawValue: ++maxValue) {}
我和++Swift已经弃用的错误,但我不知道我怎么能改变我的方法仍然正常运行.
我尝试了MaxValue + = 1,我得到了错误
'+=' produces '()', not the expected contextual result type 'Int'
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助!