gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 09:32:19 30 4
gpt4 key购买 nike

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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com