Last active
May 19, 2023 08:59
-
-
Save karthiikmk/8033574b95e5854100839e6acacc2632 to your computer and use it in GitHub Desktop.
FetchedResultsTableViewControllerWrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct FetchedResultsTableViewControllerWrapper<Entity: NSFetchRequestResult, Content: View>: UIViewControllerRepresentable { | |
public typealias UIViewControllerType = FetchedResultsTableViewController<Entity, Content> | |
/// SwiftUI | |
@Binding var searchText: String? | |
let cellContent: (Entity, _ isSelected: Bool) -> Content | |
public init( | |
searchText: Binding<String?>, | |
cellContent: @escaping (Entity, _ isSelected: Bool) -> Content | |
) { | |
self._searchText = searchText | |
self.cellContent = cellContent | |
} | |
public func makeUIViewController(context: Context) -> FetchedResultsTableViewController<Entity, Content> { | |
// NOTE: Pass your UITableViewController that Holds NSFetchedResultscontroller Here. | |
let viewController = FetchedResultsTableViewController(parentView: self, context: self.context) | |
return viewController | |
} | |
public func updateUIViewController(_ uiViewController: FetchedResultsTableViewController<Entity, Content>, context: Context) { | |
/// NOTE: Updating tableview when query changes. | |
uiViewController.update(with: searchText) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment