我对 Swift 和 iOS 开发非常陌生,但我遇到了一个错误,导致我的应用在以下设备上运行时崩溃:
iPhone 4S iPhone 5 iPad 2 iPad 视网膜
这是被标记的代码:
// bin2dec - converts binary string into decimal string
func bin2dec(input: String) -> String {
var counter = countElements(input)
var digit: Character
var power = 1
var result = 0
while counter > 0 {
digit = input[advance(input.startIndex, counter-1)]
switch digit {
case "0":
result += 0
case "1":
result += 1 * power
default:
power = power / 2
break
}
counter--
power *= 2
}
return "\(result)"
}
错误是:
Thread 1: EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0)
任何帮助将不胜感激,谢谢!