Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to swiftUI apps with SwiftData and CloudKit crashes on iOS but works on MacOS
It seems to me that your code creates a persistent CloudKit container (NSPersistentCloudKitContainer) and a SwiftData model container (ModelContainer), and that both containers use the same model and manage the same store, which triggers a conflict. This is discussed in Avoid synchronizing a store with multiple persistent containers. Assuming that you have correctly configured CloudKit in your project, when you create a SwiftData model container with the default configuration (ModelConfiguration), SwiftData creates a NSPersistentCloudKitContainer under the hood, which automatically synchronizes the data store for you, and so you don't really need to create the persistent CloudKit container. Is there any special reason why you need a persistent CloudKit container and a SwiftData model container simultaneously? Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jun ’24
What does "Allows External Storage" checkbox in the Attribute Inspector do?
For a bit of context, I store binary files of about 50KB in my Core Data. I noticed that enabling the Allows External Storage option doesn't seem to make any difference. Additionally, how does this setting work with CloudKit when using NSPersistentCloudKitContainer? Does this setting affect how the data is loaded into memory when accessed in Core Data in the app? Thank you very much!
1
0
692
Jun ’24
Reply to SwiftData with shared and private containers
SwiftData + CloudKit public or shared database isn't supported today. If that is critical to your app, I suggest that you file a feedback report to voice your need. The framework, including the new DataStore API, doesn't provide supports in that regard. You can choose to implement your own way, similar to what NSPersistentCloudKitContainer does, but that will be obviously very involved. I'd probably stick with NSPersistentCloudKitContainer, if I do need the integration with CloudKit public or shared database. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’24
Reply to SwiftData Remote Database Updates
I am not quite clear what you meant by shared remote datastore. If you referred to SwiftData + CloudKit integration enabled with ModelConfiguration.CloudKitDatabase, it is based on NSPersistentCloudKitContainer, and doesn't use the DataStore API. If your intent is to detect the changes NSPersistentCloudKitContainer made on the store and make your fetched result set up to date, you can consider observing .NSPersistentStoreRemoteChange notification, and re-fetch the data in the notification handler. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jun ’24
Reply to CloudKit in TestFlight: No sync between devices 😭
In this situation, you might consider capturing and analyzing a sysdiagnose. The following technote discusses how to do so: TN3163: Understanding the synchronization of NSPersistentCloudKitContainer The following related technote may also help: TN3164: Debugging the synchronization of NSPersistentCloudKitContainer Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jun ’24
Reply to SwiftData and CloudKit learning resource
In the SwiftData layer, the only thing you can use to configure CloudKit is ModelConfiguration.CloudKitDatabase. Underneath, SwiftData uses NSPersistentCloudKitContainer for CloudKit integration, so all the documentations and knowledges related to NSPersistentCloudKitContainer help understand how SwiftData + CloudKit works, and you can start with CloudKit mirroring. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’24
Reply to CloudKit + SwiftData
In the CloudKit environment, duplicates can indeed happen if multiple peers can create the same data. We discuss this topic in Remove duplicate data. (As of today, SwiftData + CloudKit integration uses NSPersistentCloudKitContainer, and so the content applies.) Regarding CloudKit public database, yeah, it fits the use case where any user can generate data and all users can read the data. However, SwiftData + CloudKit public database integration is not supported today. You probably need to stick with NSPersistentCloudKitContainer if to use CloudKit public database. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jun ’24
Understanding Syncing between Core Data and CloudKit Public Database using NSPersistantCloudKitContainer
Can someone please give me an overview of how sync works between Core Data and the public CloudKit database when using the NSPersistentCloudKitContainer and please point out my misunderstandings based on what I describe below? In the following code, I'm successfully connecting to the public database in CloudKit using the NSPersistentCloudKitContainer. Below is how I have Core Data and CloudKit set up for your reference. In CloudKit I have a set of PublicIconImage that I created manually via the CloudKit Console. I intend to be able to download all images from the public database at the app launch to the local device and manage them via Core Data to minimize server requests, which works but only if the user is logged in. This is the behavior I see: When the app launches, all the CloudKit images get mirrored to Core Data and displayed on the screen but only if the user is logged in with the Apple ID, otherwise nothing gets mirrored. What I was expecting: I was under the impression that when co
0
0
576
Jun ’24
Reply to Restart sync when using NSPersistentCloudKitContainer
With the following code I'm successfully turning On or Off sync between CoreData and CloudKit. I have iCloudSync saved in UserDefault / @AppStorage and controlled with a toggle switch in my app settings. This line is what turn it off description.cloudKitContainerOptions = nil, I hope it helps. class CoreDataManager: ObservableObject{ // Singleton static let instance = CoreDataManager() private let queue = DispatchQueue(label: CoreDataManagerQueue) @AppStorage(UserDefaults.Keys.iCloudSyncKey) private var iCloudSync = false lazy var context: NSManagedObjectContext = { return container.viewContext }() lazy var container: NSPersistentContainer = { return setupContainer() }() func updateCloudKitContainer() { queue.sync { container = setupContainer() } } func setupContainer()->NSPersistentContainer{ let container = NSPersistentCloudKitContainer(name: YourCoreDataContainerName) guard let description = container.persistentStoreDescriptions.first else{ fatalError(###(#function): Failed to retrieve a persis
Jun ’24
Can the NSPersistentCloudKitContainer mirror the data from the cloudKit public database to the local Core Data if the user is not logged in?
I'm currently syncing Core Data with the CloudKit public database using NSPersistentCloudKitContainer. The app starts with an empty Core Data store locally and at the app launch it downloads the data from CloudKit public database to the Core Data store, but this can only be accomplished if the user is logged in, if the user is not logged, no data gets downloaded and I get the error below. Can the NSPersistentCloudKitContainer mirror the data from the CloudKit public database to the local Core Data even if the user is not logged in? Can someone please confirm this is possible? The reason for my question is because I was under the impression that the users didn't need to be logged to read data from the public database in CloudKit but I'm not sure this applies to NSPersistentCloudKitContainer when mirroring data. I know I can fetch data directly with CloudKit APIs without the user beign logged but I need to understand if NSPersistentCloudKitContainer should in theory work with
4
0
992
Jun ’24
Reply to Can the NSPersistentCloudKitContainer mirror the data from the cloudKit public database to the local Core Data if the user is not logged in?
Here is the code that works only if the user is logged in. Again, I'm connecting to the Public database. class CoreDataManager: ObservableObject{ // Singleton static let instance = CoreDataManager() private let queue = DispatchQueue(label: CoreDataManagerQueue) private var iCloudSync = true lazy var context: NSManagedObjectContext = { return container.viewContext }() lazy var container: NSPersistentContainer = { return setupContainer() }() func updateCloudKitContainer() { queue.sync { container = setupContainer() } } func setupContainer()->NSPersistentContainer{ let container = NSPersistentCloudKitContainer(name: CoreDataContainer) guard let description = container.persistentStoreDescriptions.first else{ fatalError(###(#function): Failed to retrieve a persistent store description.) } description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) let cloudKitContainerIdentifier = iCloud.com.example.PublicDatabaseTest let options = NSPersistentCloudKitContainerOptions(containerIdent
Jun ’24
Trigger data transfer from watchOS when connectivity is restored
Hello, I have an iOS app and a companion watchOS app. Users record a workout on Apple Watch, the data for which is then transferred using both Watch Connectivity and Core Data + CloudKit (NSPersistentCloudKitContainer) to their iPhone, where it is processed and displayed. As users are recording the workout on their Apple Watch, when they finish and the transfer begins, their iPhone is often not reachable to immediately send the data using Watch Connectivity and they have no network connection (cellular or Wi-Fi). With Watch Connectivity I use transferFile from WCSession, which queues the file for transfer. With Core Data + Cloudkit I save the data and the export is queued. An undetermined amount of time may pass until the user returns to their iPhone or connects to Wi-Fi and most of the time neither of the transfer methods actually transfers the data until the user opens the watchOS app into the foreground, at which point the transfer happens immediately for both methods. I've tried a number of thing
1
0
987
Jun ’24
Reply to Trigger data transfer from watchOS when connectivity is restored
There isn't, and I see that an as-designed behavior. When a file is queued for a Watch Connectivity transfer, or a change is queued for a Core Data + CloudKit export, it is up to the system to decide when the operation should happen. That is for optimizing the overall system performance, and there is no way for developers to change the behavior. This is documented in the following API reference and technote respectively: transferFile(_:metadata:): The system attempts to send files as quickly as possible but may throttle delivery speeds to accommodate performance and power concerns. TN3164: Debugging the synchronization of NSPersistentCloudKitContainer The goal of implementing such a mechanism is to balance the use of system resources and achieve the best overall user experience on the devices. There is no API for apps to configure the timing for the synchronization. So even you have your watchOS app run in the background (for a period of time) using something like background workout processing or Hea
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’24
Reply to Tokenised text search in SwiftData help
I’ve considered turning textString into a to-many relationship by creating a Token entity but I’m unsure whether this will significantly increase overhead? I expect my database to grow very large unless I apply unique constraints on tokens and handle the CloudKit syncing myself (not using NSPersistentCloudKitContainer). Also in my app if many results are fetched (between 1000 to 100,000 matches) from the predicate I will need to perform an additional filter that can only be done in-memory, in this scenario would I need to perform both the predicate and filter in batches?
Topic: Community SubTopic: Apple Developers Tags:
Jul ’24