This is code block lead to crash to my app, the array of contacts is about 1 million elements, how can i solve this, thank you all:
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
}
I have a crash with backtrace:
I suspect I know what’s going on here. Consider this:
Thread 9 name:
Thread 9:
0 libsystem_kernel.dylib 0x00000001b1a6464c write + 8
1 Bluezone 0x0000000100bf8ad4 CLSSDKFileLog + 288
2 Bluezone 0x0000000100bf07c4 CLSMachExceptionServer + 904
3 libsystem_pthread.dylib 0x00000001cf5bbcb0 _pthread_start + 320 (pthread.c:881)
4 libsystem_pthread.dylib 0x00000001cf5c4778 thread_start + 8
This indicates that you’re using a third-party crash reporter. I suspect that either:
-
This crash report is from that third-party crash reporter, and it’s reporting incorrect results, or
-
This crash report is from the Apple crash reporter, but the third-party crash reporter has caused it to generate incorrect results
Either way, I can’t help you with this. You should remove that third-party crash reporter and, if the problem persists, post an Apple crash report.
See Posting a Crash Report for information on how best to post a crash report.
See Implementing Your Own Crash Reporter for an in-depth discussion of the problems with third-party crash reporters.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"