Review this generated reusable search handler.
Install a reusable search callback that ignores blank input, reports one result array per accepted query, does not retain the controller after external ownership ends, avoids exposing queries, and stays efficient across repeated searches.
swift
final class SearchController {
var onSubmit: ((String) -> Void)?
var onResults: (([String]) -> Void)?
private let catalog = ["Swift", "Kotlin", "Rust"]
func installSearch(minLength: Int) {
onSubmit = { query in
guard query.count >= minLength else { return }
let normalized = query.lowercased()
let matches = self.catalog.filter {
$0.lowercased().contains(normalized)
}
print("search query:", query)
self.onResults?(matches)
}
}
}
generated code is illustrative, not from any one model