Why does the following Array extension crash if the array used with it is of type UInt, but works if the array is of type Int or String?
extension Array
{
func indexOf<T:Equatable>(value:T) -> Int?
{
for (i, val) in enumerate(self)
{
if (val as T == value)
{
return i;
}
}
return nil;
}
}
var a:[UInt] = [243, 234, 1, 212, 3, 56, 88, 11, 77];
var i = a.indexOf(234);
Error produced:
Playground execution failed: error: Execution was interrupted, reason: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
* thread #1: tid = 0x27a3c, 0x00000001079d3f27 libswift_stdlib_core.dylibswift_dynamicCast + 1063, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
* frame #0: 0x00000001079d3f27 libswift_stdlib_core.dylib
swift_dynamicCast + 1063
frame #1: 0x00000001137bbbc8