Hi @b_rare, your message helped knock my brain into gear when I was really confused, thank you... in case this helps you or any other lost devs...
I was seeing this same Task or actor isolated value cannot be sent warning on Xcode 16.1 when I tried to do something very similar:
Unable to move from nonisolated to @MainActor with a Task
extension ViewController: MKLocalSearchCompleterDelegate {
nonisolated func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
Task { @MainActor in
searchBar.searchTextField.searchSuggestions = completer.results.map { result in
UISearchSuggestionItem(localizedSuggestion: result.title, localizedDescription: result.description)
}
}
}
Fix
I have made the errors go away by mapping the results properties to a tuple with just the String values I needed:
extension ViewController: MKLocalSearchCompleterDelegate {
nonisolated func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
let results = completer.results.map { result in
(result.title, result.description)
}
Task { @MainActor in
searchBar.searchTextField.searchSuggestions = results.map { result in
UISearchSuggestionItem(localizedSuggestion: result.0, localizedDescription: result.1)
}
}
}
Why it works
My understanding is that since completer: MKLocalSearchCompleter and completer.results: [MKLocalSearchCompletion] are both classes (reference types) and not final, they are therefore NOT Sendable.
Strings, however, are value types, so they are Sendable and can be passed between isolation domains.
Post
Replies
Boosts
Views
Activity
I had this issue when I set the image icons using JPEGs instead of PNGs. I swapped the images over, no more issues.
I had this issue when I set the image icons using JPEGs instead of PNGs. I swapped the images over, no more issues.