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 Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.