Created
March 27, 2025 12:46
-
-
Save yccheok/5af29dcb6a23d2fdb96d695169e80fe9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@globalActor actor MyGlobalActor : GlobalActor { | |
static let shared = MyGlobalActor() | |
} | |
extension MoveNoteViewController: UISearchBarDelegate { | |
@MyGlobalActor | |
private func filterNotes(_ text: String) async -> [Note] { | |
if text.isEmpty { | |
return await notes | |
} else { | |
let notes = await self.notes! | |
let idToFolderMap = await self.idToFolderMap! | |
return notes.filter { | |
let emoji = $0.emoji | |
let title = $0.title | |
var folderName: String? = nil | |
if let folderId = $0.folderId { | |
folderName = idToFolderMap[folderId]?.name ?? "" | |
} | |
return | |
emoji.localizedCaseInsensitiveContains(text) || | |
title.localizedCaseInsensitiveContains(text) || | |
(folderName?.localizedCaseInsensitiveContains(text) ?? false) | |
} | |
} | |
} | |
@MainActor | |
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { | |
let text = searchText.trim() | |
if text.isEmpty { | |
applySnapshot(snapshot: getSnapshot(notes: notes)) | |
} else { | |
Task { | |
let filteredNotes = await filterNotes(text) | |
if searchBar.text?.trim() == text { | |
applySnapshot(snapshot: getSnapshot(notes: filteredNotes)) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment