所以我的
Xcode项目中有这个小算法,它不再有效 – 它告诉我,我不能添加一个数字到另一个数字,无论我尝试.
注意:
在将目标更改为iOS 7.0之前,一切正常工作.
我不知道这是否与它有任何关系,但即使我将其切换回iOS 8,它给了我一个错误,我的构建失败了.
码:
var delayCounter = 100000 for loop in 0...loopNumber { let redDelay: NSTimeInterval = NSTimeInterval(arc4random_uniform(100000) + delayCounter) / 30000 let blueDelay: NSTimeInterval = NSTimeInterval(arc4random_uniform(100000) + delayCounter) / 30000 let yellowDelay: NSTimeInterval = NSTimeInterval(arc4random_uniform(100000) + delayCounter) / 30000 let greenDelay: NSTimeInterval = NSTimeInterval(arc4random_uniform(100000) + delayCounter) / 30000 }
解决方法
麻烦的是,delayCounter是一个Int,但是arc4random_uniform返回一个UInt32.您需要将delayCounter声明为UInt32:
var delayCounter: UInt32 = 100000 let redDelay = NSTimeInterval(arc4random_uniform(100000) + delayCounter) / 30000
或者将arc4random的结果转换为Int:
var delayCounter:Int = 100000 let redDelay = NSTimeInterval(Int(arc4random_uniform(100000)) + delayCounter) / 30000