Here's an implementation of binary search in Swift:
main.swift399 chars18 linesTo perform binary search, call this function passing it the array you want to search and the key you want to find. The function will return the index of the key in the array, or nil if the key is not found.
Here's an example of how to use it:
main.swift175 chars7 linesThis will output "Found 5 at index 4".
gistlibby LogSnag