我在Xcode中收到随机的EXC_BAD_INSTRUCTION错误,这让我发疯了。
这是我的班级:
import Foundation
import BigInteger
import CryptoSwift
class NonceController: NSObject {
func generateNonce(secret: NSString!, timeoutSeconds: Int) -> NSString {
var nonce: NSString = ""
println(secret.length < 10)
var test: NSString = "testsasa"
if test.length < 10 { // EXC_BAD_INSTRUCTION (code=EXC_i386_INVOP, subcode=0x0) thrown here
}
if secret.length < 10 {
//INVALID, throw exception
} else {
//valid params
var salt: BigInteger = generateSalt()
var dateDouble = Int(NSDate().timeIntervalSince1970) * 1000
var currentMillies: BigInteger = BigInteger(dateDouble)
var maxTime = currentMillies + timeoutSeconds * 1000
var maxTime: Int = Int(currentMillies + (Int(timeoutSeconds) * 1000))
var toHash = "\(salt)\(secret)\(maxTime)"
var hash: String = toHash.sha1()!.lowercaseString
nonce = "\(salt),\(maxTime),\(hash)"
}
return nonce // If I remove the test length check it is thrown here instead
}
func generateSalt() -> BigInteger {
...
}
}
如果删除该虚拟测试,则会在返回行上抛出异常。
谁能告诉我为什么会这样?我认为这是Xcode的一个错误,因为这些错误似乎随机抛出。我可以在其他类中使用此代码,它运行正常......
干杯!