Razvan Constantin
Razvan Constantin

Reputation: 30

Xcode problem AppDelegate with Firebase - 'NSPersistentCloudKitContainer'

newbie in UIKit/SwiftUI here, now I'm working on a SwiftUI App with UIKit Life Cycle and I got this problem

Cannot find type 'NSPersistentCloudKitContainer' in scope

The code is that:

import UIKit
import Firebase

@main
class AppDelegate: UIResponder, UIApplicationDelegate {



    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        return true
    }

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        //nothing
    }

    lazy var persistentContainer: NSPersistentCloudKitContainer = { **Here is problem**
        let container = NSPersistentCloudKitContainer(name: "app_Swiftui")
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
        return container
    }()

    func saveContext () {
        let context = persistentContainer.viewContext
        if context.hasChanges {
            do {
                try context.save()
            } catch {
                let nserror = error as NSError
                fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
            }
        }
    }

}

I get Build Failed everytime and I get this error. Can somebody help me?

Upvotes: 1

Views: 174

Answers (2)

Debashish M
Debashish M

Reputation: 323

Here you go:
NSPersistentCloudKitContainer is a subclass of NSPersistentContainer capable of managing both CloudKit-backed and noncloud stores.

So its a Core Data!

Declarer it on top:

import CoreData

For more details read this page Apple Doc also this can help Apple Doc2

Upvotes: 1

goatofanerd
goatofanerd

Reputation: 468

NSPersistendCloudKitContainer is a CoreData class.

import CoreData and you'll be on your way!

Upvotes: 4

Related Questions