I have a array of contacts (about 1 millions elements), i must compare many of times the id of a contact to find out contact i need (the list was order by id so i'm using binary search). It did crash, this is my code and backtrace:
struct Contact {
let blIdContact: String
let timeStamp: Int64
}
func binarySearch(in contacts: [Contact], for value: String) -> Int? {
var left = 0
var right = contacts.count - 1
while left <= right {
let middle = Int(floor(Double(left + right) / 2.0))
if contacts[middle].blIdContact < value {
left = middle + 1
} else if contacts[middle].blIdContact > value {
right = middle - 1
} else {
return middle
}
}
return nil
}
This is backtrace at crashed thread:
Thread 25 Crashed:
0 libobjc.A.dylib 0x00000001b38771c8 objc_msgSend + 8
1 libswiftCore.dylib 0x00000001a2b1a464 _foreignNormalize(readIndex:endIndex:guts:outputBuffer:icuInputBuffer:icuOutputBuffer:) + 236 (StringBridge.swift:159)
2 libswiftCore.dylib 0x00000001a2b231cc _StringGutsSlice._slowCompare(with:expecting:) + 3464 (StringComparison.swift:375)
3 libswiftCore.dylib 0x00000001a2b2115c _stringCompareInternal(_:_:expecting:) + 308 (StringComparison.swift:185)
4 Bluezone 0x00000001023f1450 binarySearch(in:for:) + 37968 (Utils.swift:46)
This is full backtrace:
Crash when compare 2 String many of times
See my response on your other thread.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"