TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Trouble getting CloudKit to work with Core Data

Forums > Swift

Hi all, I followed the tutorial on Apple's website (https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/setting_up_core_data_with_cloudkit), but for some reason the persistent store is failing to load. I've tried looking around for a clear answer, but to no avail, it's starting to drive me crazy lmao. The store was working before I applied the capabilities too, which is even more confusing. Here is the code for my data controller:

import CoreData
import Foundation

class DataController: ObservableObject {
    let container = NSPersistentCloudKitContainer(name: "TaskDataModel")

    init() {
        guard let description = container.persistentStoreDescriptions.first else {
            fatalError("Container descriptions not loaded")
        }
        description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
        container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
        container.viewContext.automaticallyMergesChangesFromParent = true
        container.loadPersistentStores { description, error in
            if let error = error {
                print("Core Data failed to load: \(error.localizedDescription)")
            }
        }
    }
}

My CoreData model is called "TaskDataModel", but my CloudKit container has a different name. Could that be cause for a problem? My full repo is here: https://github.com/aabagdi/TaskMan

Thank you for any help!

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.