iOS Swift - EXC_BAD_INSTRUCTION on certain devices
I'm very new to Swift and iOS development but I've come across a bug that is causing my app to crash when running on the following devices: iPhone 4S iPhone 5 iPad 2 iPad Retina Here is the code that is being flagged up: // 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 }