Post

Replies

Boosts

Views

Activity

Reply to SwiftData Predicate for optional to-many (as required by CloudKit) relationships crashes
I’ve been looking for a solution to this for a while. I finally found this method at the bottom of another thread: let searchPredicate = #Predicate<SectionsSD> { $0.toArticles?.contains(filter) ?? false } Which appears to be working for me as an empty/nil check here: let descriptor = FetchDescriptor<Flashcard>( predicate: #Predicate { $0.annotations?.contains { _ in true } ?? false } ) I was able to combine it with an expression to actually look inside the to-many side: let hasAnnotation = #Expression<Flashcard, Bool> { card in if let annotations = card.annotations { return annotations.contains { annotation in annotation.reference == "hola" } } else { return false } } let descriptor = FetchDescriptor<Flashcard>( predicate: #Predicate { hasAnnotation.evaluate($0) } ) Seems to be working so far.
2w
Reply to Strange behavior with 100k+ records in NSPersistentCloudKitContainer
I’m having a similar problem. I found a reddit post about this issue where the author writes, “I’m guessing it only shows up for devs who bulk import/delete during testing, while normal users with a few hundred records never notice.” Which makes sense because I am also bulk importing. I’m seeing about a 6-8 times increase between the local storage and CloudKit. (Specifically, 15k records comes out to around 13mb of local storage, but 100mb with CloudKit enabled. ANSCKRECORDMETADATA appears to be the main culprit.) I’m making a flashcard app, and of course users can import as many cards as they want, which could become a storage problem pretty quickly. From my understanding, and as you mentioned, a storage increase is expected. But the increase I’m seeing just seems excessive. … Or is it? I can’t really find anything on what to expect. I wonder if there’s something I can change in the model to make this work. Or maybe the problem is unique to NSPersistentCloudKitContainer and I should look at other sync options, but your second experiment seems to discount that. The poster I mentioned earlier talked about trying to clear the CloudKit metadata tables using NSPersistentHistoryChangeRequest.deleteHistory(before:), but was unable to do so due to using SwiftData (like I am). I’m a bit of an amateur and I’m pretty out of my depth, so I’d rather stick to NSPersistentCloudKitContainer if possible. In every other respect, syncing with SwiftData has been easy and is working perfectly—it’s just the storage size I’m worried about.
Topic: App & System Services SubTopic: iCloud Tags:
Nov ’25
Reply to SwiftData Predicate for optional to-many (as required by CloudKit) relationships crashes
I’ve been looking for a solution to this for a while. I finally found this method at the bottom of another thread: let searchPredicate = #Predicate<SectionsSD> { $0.toArticles?.contains(filter) ?? false } Which appears to be working for me as an empty/nil check here: let descriptor = FetchDescriptor<Flashcard>( predicate: #Predicate { $0.annotations?.contains { _ in true } ?? false } ) I was able to combine it with an expression to actually look inside the to-many side: let hasAnnotation = #Expression<Flashcard, Bool> { card in if let annotations = card.annotations { return annotations.contains { annotation in annotation.reference == "hola" } } else { return false } } let descriptor = FetchDescriptor<Flashcard>( predicate: #Predicate { hasAnnotation.evaluate($0) } ) Seems to be working so far.
Replies
Boosts
Views
Activity
2w
Reply to Strange behavior with 100k+ records in NSPersistentCloudKitContainer
I’m having a similar problem. I found a reddit post about this issue where the author writes, “I’m guessing it only shows up for devs who bulk import/delete during testing, while normal users with a few hundred records never notice.” Which makes sense because I am also bulk importing. I’m seeing about a 6-8 times increase between the local storage and CloudKit. (Specifically, 15k records comes out to around 13mb of local storage, but 100mb with CloudKit enabled. ANSCKRECORDMETADATA appears to be the main culprit.) I’m making a flashcard app, and of course users can import as many cards as they want, which could become a storage problem pretty quickly. From my understanding, and as you mentioned, a storage increase is expected. But the increase I’m seeing just seems excessive. … Or is it? I can’t really find anything on what to expect. I wonder if there’s something I can change in the model to make this work. Or maybe the problem is unique to NSPersistentCloudKitContainer and I should look at other sync options, but your second experiment seems to discount that. The poster I mentioned earlier talked about trying to clear the CloudKit metadata tables using NSPersistentHistoryChangeRequest.deleteHistory(before:), but was unable to do so due to using SwiftData (like I am). I’m a bit of an amateur and I’m pretty out of my depth, so I’d rather stick to NSPersistentCloudKitContainer if possible. In every other respect, syncing with SwiftData has been easy and is working perfectly—it’s just the storage size I’m worried about.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Nov ’25