Post

Replies

Boosts

Views

Activity

Can't start a game in Game Center (GameKit)
I'm working in a game that it was working perfectly with Game Center (remote game with 1 remote player), but since last Sunday I'm having errors when I try to start a remote game. I have 2 errors, one says FAILED when I invite a friend to play. In this case, the other device never gets the notification. The other error sent the notification, but when I tap on it (on the other device), it fails saying that it couldn't communicate with the server). The main device it says "INVITED" but it doesn't say anything else. I haven't found anyone else having the same issue, so I wonder if it's my fault, although I haven't change that part of the code since the last time I tested it. Is it someone else here having similar problems? or knows what should I review? thank you all, and have a great year!
1
0
1.1k
Jan ’24
Understanding the warning and how to fix it: Non-sendable cannot cross actor boundary
Hi all, I'm testing the first beta for iOS 16.4 and Xcode 14.3 and I'm getting these warnings that I kind of understand, but I don't know and I haven't found how to solve them. For example this code that is just a simplified example: @MainActor class ATextModel: ObservableObject {     @Published private(set) var record: CKRecord?     func getData() async {         let database = CKContainer.default().publicCloudDatabase         let query = CKQuery(recordType: "Test", predicate: NSPredicate(value: true))         do {             let results = try await database.records(matching: query)             self.record = try results.matchResults.first?.1.get()         } catch {             print("Error: \(error.localizedDescription)")         }     } } Is giving me 2 warnings: Non-sendable type '(matchResults: [(CKRecord.ID, Result<CKRecord, any Error>)], queryCursor: CKQueryOperation.Cursor?)' returned by call from main actor-isolated context to non-isolated instance method 'records(matching:inZoneWith:desiredKeys:resultsLimit:)' cannot cross actor boundary Non-sendable type 'CKQuery' exiting main actor-isolated context in call to non-isolated instance method 'records(matching:inZoneWith:desiredKeys:resultsLimit:)' cannot cross actor boundary Does someone has a hint on how I should do this now? This might be just an error in the beta, but I don't really think that.
5
3
9.2k
Sep ’23
Slow List refresh when using coredata NSFetchedResultsController
I'm making a test with SwiftUI and my app (that uses coredata) and I'm having some problems.I managed to make to work NSFetchedResultsController and it works nicely. The problem occurs when I made searches (changing the predicate) and the List must update the changes. It seems that not only the visible "rows" are compared between the old and new fetchedObjets (as before with the old UITableView), but the entire list and that is extremely slow.The logs that I'm seeing with SQLDebug level 4 are showing me that all objets are being loaded in batches of 20 objets (fetchBatchSize = 20).This is my code for the List View:struct OrderListView: View { @ObservedObject var searchOrderFilter: SearchOrderFilter var body: some View { List { SearchView(searchText: $searchOrderFilter.searchText, selectedOption: $searchOrderFilter.selectedOptionIndex, placeholder: "Search", options: ["Address", "Work", "Client", "Phone", "PO"]) ForEach(searchOrderFilter.fetchedResultsController.fetchedObjects!, id: \.objectID) { (order) in OrderCellView(order: order) } } .navigationBarItems(trailing: HStack(alignment: .center, spacing: 20.0) { Button(action: {}, label: { Text("Select") }) Button(action: {}, label: { Text("Filter") }) Button(action: {}, label: { Text("+") }) }) .navigationBarBackButtonHidden(false) .listStyle(DefaultListStyle()) } }And this is my current (testing) SearchOrderFilter class:final class SearchOrderFilter: NSObject, ObservableObject, NSFetchedResultsControllerDelegate { public let objectWillChange = PassthroughSubject&lt;SearchOrderFilter, Never&gt;() private var filterType: Order.FilterType @Published var searchText: String = "" { didSet { if oldValue != searchText { fetchOrders() } } } @Published var selectedOptionIndex: Int = 0 { didSet { if oldValue != selectedOptionIndex { fetchOrders() } } } public func setFilter(filterType: Order.FilterType) -&gt; SearchOrderFilter { if self.filterType != filterType { self.filterType = filterType self.searchText = "" self.selectedOptionIndex = 0 fetchOrders() } return self } init(filterType: Order.FilterType) { self.filterType = filterType super.init() updateCounterForCommonFilter() } public var fetchedResultsController: NSFetchedResultsController&lt;Order&gt; = NSFetchedResultsController(fetchRequest: Order.filteredFetchRequest(filterType: .none), managedObjectContext: CoreDataCache.sharedInstance.persistentContainer.viewContext, sectionNameKeyPathme: private func fetchOrders() { let filterSecondaryType = Order.FilterSecondaryType(rawValue: selectedOptionIndex) ?? Order.FilterSecondaryType.none let fetchRequest = Order.filteredFetchRequest(filterType: self.filterType, filterBy: filterSecondaryType, se fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: CoreDataCache.sharedInstance.persistentContainer.viewContext, sectionNameKeyPath: nil, cacheName: nil) fetchedResultsController.delegate = self //_fetchedResultsController.fetchRequest.predicate = fetchRequest.predicate do { print("perform fetch") try fetchedResultsController.performFetch() } catch { objectWillChange.send(self) //_fetchedResultsController = nil } } // MARK: NSFetchedResultsControllerDelegate func controllerWillChangeContent(_ controller: NSFetchedResultsController&lt;NSFetchRequestResult&gt;) { print("controller will change content") objectWillChange.send(self) } }Forgive me if the last code doesn't look right, I had some problems copying it and it's my test class (where I'm trying many different approches).I also tried using the @FetchRequest but I couldn't find how I can change the predicate when I'm doing new searches.If someone has a tip or any comment, I'd appreciate it.Thank you
3
0
2.9k
Apr ’22
Can't start a game in Game Center (GameKit)
I'm working in a game that it was working perfectly with Game Center (remote game with 1 remote player), but since last Sunday I'm having errors when I try to start a remote game. I have 2 errors, one says FAILED when I invite a friend to play. In this case, the other device never gets the notification. The other error sent the notification, but when I tap on it (on the other device), it fails saying that it couldn't communicate with the server). The main device it says "INVITED" but it doesn't say anything else. I haven't found anyone else having the same issue, so I wonder if it's my fault, although I haven't change that part of the code since the last time I tested it. Is it someone else here having similar problems? or knows what should I review? thank you all, and have a great year!
Replies
1
Boosts
0
Views
1.1k
Activity
Jan ’24
Understanding the warning and how to fix it: Non-sendable cannot cross actor boundary
Hi all, I'm testing the first beta for iOS 16.4 and Xcode 14.3 and I'm getting these warnings that I kind of understand, but I don't know and I haven't found how to solve them. For example this code that is just a simplified example: @MainActor class ATextModel: ObservableObject {     @Published private(set) var record: CKRecord?     func getData() async {         let database = CKContainer.default().publicCloudDatabase         let query = CKQuery(recordType: "Test", predicate: NSPredicate(value: true))         do {             let results = try await database.records(matching: query)             self.record = try results.matchResults.first?.1.get()         } catch {             print("Error: \(error.localizedDescription)")         }     } } Is giving me 2 warnings: Non-sendable type '(matchResults: [(CKRecord.ID, Result<CKRecord, any Error>)], queryCursor: CKQueryOperation.Cursor?)' returned by call from main actor-isolated context to non-isolated instance method 'records(matching:inZoneWith:desiredKeys:resultsLimit:)' cannot cross actor boundary Non-sendable type 'CKQuery' exiting main actor-isolated context in call to non-isolated instance method 'records(matching:inZoneWith:desiredKeys:resultsLimit:)' cannot cross actor boundary Does someone has a hint on how I should do this now? This might be just an error in the beta, but I don't really think that.
Replies
5
Boosts
3
Views
9.2k
Activity
Sep ’23
Slow List refresh when using coredata NSFetchedResultsController
I'm making a test with SwiftUI and my app (that uses coredata) and I'm having some problems.I managed to make to work NSFetchedResultsController and it works nicely. The problem occurs when I made searches (changing the predicate) and the List must update the changes. It seems that not only the visible "rows" are compared between the old and new fetchedObjets (as before with the old UITableView), but the entire list and that is extremely slow.The logs that I'm seeing with SQLDebug level 4 are showing me that all objets are being loaded in batches of 20 objets (fetchBatchSize = 20).This is my code for the List View:struct OrderListView: View { @ObservedObject var searchOrderFilter: SearchOrderFilter var body: some View { List { SearchView(searchText: $searchOrderFilter.searchText, selectedOption: $searchOrderFilter.selectedOptionIndex, placeholder: "Search", options: ["Address", "Work", "Client", "Phone", "PO"]) ForEach(searchOrderFilter.fetchedResultsController.fetchedObjects!, id: \.objectID) { (order) in OrderCellView(order: order) } } .navigationBarItems(trailing: HStack(alignment: .center, spacing: 20.0) { Button(action: {}, label: { Text("Select") }) Button(action: {}, label: { Text("Filter") }) Button(action: {}, label: { Text("+") }) }) .navigationBarBackButtonHidden(false) .listStyle(DefaultListStyle()) } }And this is my current (testing) SearchOrderFilter class:final class SearchOrderFilter: NSObject, ObservableObject, NSFetchedResultsControllerDelegate { public let objectWillChange = PassthroughSubject&lt;SearchOrderFilter, Never&gt;() private var filterType: Order.FilterType @Published var searchText: String = "" { didSet { if oldValue != searchText { fetchOrders() } } } @Published var selectedOptionIndex: Int = 0 { didSet { if oldValue != selectedOptionIndex { fetchOrders() } } } public func setFilter(filterType: Order.FilterType) -&gt; SearchOrderFilter { if self.filterType != filterType { self.filterType = filterType self.searchText = "" self.selectedOptionIndex = 0 fetchOrders() } return self } init(filterType: Order.FilterType) { self.filterType = filterType super.init() updateCounterForCommonFilter() } public var fetchedResultsController: NSFetchedResultsController&lt;Order&gt; = NSFetchedResultsController(fetchRequest: Order.filteredFetchRequest(filterType: .none), managedObjectContext: CoreDataCache.sharedInstance.persistentContainer.viewContext, sectionNameKeyPathme: private func fetchOrders() { let filterSecondaryType = Order.FilterSecondaryType(rawValue: selectedOptionIndex) ?? Order.FilterSecondaryType.none let fetchRequest = Order.filteredFetchRequest(filterType: self.filterType, filterBy: filterSecondaryType, se fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: CoreDataCache.sharedInstance.persistentContainer.viewContext, sectionNameKeyPath: nil, cacheName: nil) fetchedResultsController.delegate = self //_fetchedResultsController.fetchRequest.predicate = fetchRequest.predicate do { print("perform fetch") try fetchedResultsController.performFetch() } catch { objectWillChange.send(self) //_fetchedResultsController = nil } } // MARK: NSFetchedResultsControllerDelegate func controllerWillChangeContent(_ controller: NSFetchedResultsController&lt;NSFetchRequestResult&gt;) { print("controller will change content") objectWillChange.send(self) } }Forgive me if the last code doesn't look right, I had some problems copying it and it's my test class (where I'm trying many different approches).I also tried using the @FetchRequest but I couldn't find how I can change the predicate when I'm doing new searches.If someone has a tip or any comment, I'd appreciate it.Thank you
Replies
3
Boosts
0
Views
2.9k
Activity
Apr ’22