Post

Replies

Boosts

Views

Activity

Will the new Coredata+CloudKit support sharing
I have an app that uses CloudKit to share records between multiple users and coredata as a local read-write cache.I'm interested in the new automatic coredata+cloudkit integration, but I'm not sure how or if this will support sharing records with other cloudkit users.I haven't test iOS 13 beta, yet, but I'm planning to do it in the next weeks.Does someone have any knowledge about this? My bet is that is not supported, but I want to be sure.Thank you
7
0
1.8k
Jun ’19
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<SearchOrderFilter, Never>() 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) -> 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<Order> = 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<NSFetchRequestResult>) { 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.7k
Aug ’19
CKQuery predicate fails with ANY-BEGINSWITH
Reading the CKQuery documentation, I found this example: [NSPredicate predicateWithFormat:@"ANY favoriteColors BEGINSWITH %@", matchString] If favoriteColors is a String List, that means that I can search for the beginning of each value in the string list, however if I tried this, the app crashes. Terminating app due to uncaught exception 'CKException', reason: 'Invalid predicate: ANY nameSearch BEGINSWITH "Do" In my test, nameSearch is a String List. I don't know if I'm understand the documentation wrong and favoriteColors is not a string list, but then why they are using ANY?
1
0
829
Jul ’21
How to track why an execution is paused sometimes
I'm testing the new concurrency (actor, await, group, etc) and I'm having a weird (for me) problem. I have a method that executes 9 concurrent process using withThrowingTaskGroup. Each process starts fetching data from coredata, each in their own context. I start the execution tapping a button. The problem is that sometimes the execution get paused, usually in a very similar place (in an await context.perform{}). The code inside the perform executes well, but it's like the await doesn't return control to the next line of code. The curious thing is that if I tap the button again, the old paused process continues and finishes, while the second process runs its own execution. Is there any way to track what is happening?
0
0
751
Jul ’21
Why List rows never animate as expected?
I always have problems when trying to animate rows. At this moment I'm trying to add content to a row when the user taps over the cell (to show some details). I'm using withAnimation and a @state variable to control when the extra content appears. The problem is that the animation it's so weird. It's like the cell resize first without animation, then the current content starts moving from the center while the new content appears. What I want is that the current content stays on top of the row while the added content appears from the bottom, making the cell higher. Is there any way to really control transitions and animations when using List ?
0
0
690
Jul ’21
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
7.5k
Feb ’23
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
687
Jan ’24