小编Chr*_*ani的帖子

如何使我的增量或Swift 3友好?

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)

非常感谢您的帮助!

swift swift3

0
推荐指数
1
解决办法
3076
查看次数

标签 统计

swift ×1

swift3 ×1