Post

Replies

Boosts

Views

Activity

Reply to Is there a way to use Core Data/CloudKit to store and move data with Swift UI in Xcode 12?
When following this, i keep getting the error, cannot find type "MyHumidor" in scope. My App.swift and the CoreData.swift files below (created the coredata.swift to hold the public class) import SwiftUI @main struct My_HumidorApp: App { 		let context = PersistentCloudKitContainer.persistentContainer.viewContext 		var body: some Scene { 				WindowGroup { 						ContentView().environment(\.managedObjectContext, context) 				} 		} } // //	CoreData.swift //	My Humidor // //	Created by Adam Hewitt on 28/06/2020. // import Foundation import CoreData public class PersistentCloudKitContainer { 		// MARK: - Define Constants / Variables 		public static var context: NSManagedObjectContext { 				return persistentContainer.viewContext 		} 		// MARK: - Initializer 		private init() {} 		// MARK: - Core Data stack 		public static var persistentContainer: NSPersistentContainer = { 				let container = NSPersistentContainer(name: "My_Humidor") 				container.loadPersistentStores(completionHandler: { (storeDescription, error) in 						if let error = error as NSError? { 								fatalError("Unresolved error \(error), \(error.userInfo)") 						} 				}) 				container.viewContext.automaticallyMergesChangesFromParent = true 				container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy 				return container 		}() 		// MARK: - Core Data Saving support 		public static 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)") 						} 				} 		} } This is the start of my content view: 		import SwiftUI struct ContentView: View { 		@Environment(\.managedObjectContext) var moc 		@FetchRequest(entitiy: MyHumidors.entity(), sortDescriptors:[]) var humidor: FetchRequest<MyHumidors> 		 		 Any ideas what is causing this from a code perspective?
Jun ’20
Reply to Getting Started With Core Data SwiftUI XCode12
Thanks for this, I will take a look. What I am finding tricky is that everything keeps changing. Now, for example, there is no app delegate file made when you start a new xplatform app. So I am assuming that I now use the xxxxxxApp.swift file instead. On Xcode 11 the app delegate was prepopulated with a lot of code and comments, whereas this new file has almost nothing in it. Thanks all the same, it is appreciated. Adam
Jun ’20