Struct AccountData { let accountId : String let accountName : String //省略 } actor AccountDataStore { //******Error: EXC_BAD_ACCESS など static var accountDataStore : [String:AccountData] = [:] //******Error: unrecognized selector sent to instance など static func addAccountData(_ data: AccountData) { AccountDataStore.accountDataStore[data.accountId] = data } static func addAccountDataArray(_ data: [AccountData]){ for data in data{ AccountDataStore.accountDataStore.updateValue(data, forKey: data.accountId) } } static func removeAccountData(_ accountId: String) { AccountDataStore.accountDataStore.removeValue(forKey: accountId) } static func removeAccountAllData(){ AccountDataStore.accountDataStore.removeAll() } static func removeAccountDataArray(_ data:[String]){ for data in data{ AccountDataStore.accountDataStore.removeValue(forKey: data) } } } //利用例 func getAccount(id:String)->[AccountData]{ if let account = AccountDataStore.accountDataStore[id]{ return account }else{ //server request AccountDataStore.addAccountData(data) return data } } func getAccountAsync(id:String) async -> [AccountData]{ if let account = AccountDataStore.accountDataStore[id]{ return account }else{ //server request AccountDataStore.addAccountData(data) return data } } func addAccountDataWithIdsAsync(accountIds:[String]) async throws { try await withThrowingTaskGroup(of: AccountData.self){ group in for id in accountIds{ group.addTask{ return try await getAccountAsync(id:id) } } for try await (id, data) in group{ await AccountDataStore.addAccountData(data) } } }