Developer" var organizerOf = "HAKATA.swift" var favoriteLanguage = "Swift" var twitter = "@lovee" var qiita = "lovee" var github = "el-hoshino" var additionalInfo = """ ߴࢁߦ͖ͬͯͨΒࡢͷωΧϑΣ νΣοΫΞτ͢ΔͷΕͪΌͬͯ ߴࢁ͔ΒͷΓʹ߄͓ͯͯళߦͬͨΒौʹר͖ࠐ·ΕͪΌͬͨ """ final class Me: Developable, Talkable {
maxHistoryCount = 50 @discardableResult @MainActor private func waitForHistories() async -> [History] { while true { if let histories { return histories } await Task.yield() } } //... } extension HistoryManager: HistoryManagerProtocol { public func addHistory(_ history: History) async { await waitForHistories() await MainActor.run { // If history already exist, remove it before adding it so it'll be listed at last. while let existHistoryIndex = histories?.firstIndex(of: history) { histories?.remove(at: existHistoryIndex) } histories?.append(history) // If the list is too long, remove the oldest history. while (histories?.count ?? 0) >= maxHistoryCount { self.histories?.removeFirst() } } } public func deleteHistory(_ history: History) async { await waitForHistories() // If the history is not in the list, do nothing. await MainActor.run { [self] in while let index = histories?.firstIndex(of: history) { self.histories?.remove(at: index) } } } @MainActor public func getHistories() -> [History] { // Return the list in the order of the most recent history. guard let histories else { return [] } return histories.reversed() } }