Skip to content

Instantly share code, notes, and snippets.

@markvanwijnen
Last active September 9, 2020 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markvanwijnen/9f4469573d7c29d940a32a386ca3b4ac to your computer and use it in GitHub Desktop.
Save markvanwijnen/9f4469573d7c29d940a32a386ca3b4ac to your computer and use it in GitHub Desktop.
Part 1 of building the NavigationSearch.
import SwiftUI
import UIKit
struct NavigationSearch: UIViewControllerRepresentable {
typealias UIViewControllerType = Wrapper
func makeCoordinator() -> Coordinator {
Coordinator(representable: self)
}
func makeUIViewController(context: Context) -> Wrapper {
Wrapper()
}
func updateUIViewController(_ wrapper: Wrapper, context: Context) {
wrapper.searchController = context.coordinator.searchController
}
class Coordinator: NSObject {
let representable: NavigationSearch
let searchController: UISearchController
init(representable: NavigationSearch) {
self.representable = representable
self.searchController = UISearchController(searchResultsController: nil)
super.init()
}
}
class Wrapper: UIViewController {
var searchController: UISearchController? {
get {
self.parent?.navigationItem.searchController
}
set {
self.parent?.navigationItem.searchController = newValue
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment