Post

Replies

Boosts

Views

Activity

Reply to Failed Registering Bundle Identifier of watch app
Thanks for your investigation and suggestion. But i think step 4 and 5 were the other way round. I actually submitted my watch OS app to store so i guess i first registered it with my team. and somehow another team could register it afterwards and now it's not possible anymore for me. But i will try to change the last component of my app to something other than .watchkitapp. I thought it's mandatory to have this naming convetion from what i read on the internet. Edit: Tried to update it but Xcode is not allowing to upload to AppStoreConnect Invalid Bundle Identifier. Attempting to change bundle identifier from (myappBundleID).watchkitapp to (myappBundleID).(newName) is disallowed for bundle Sensor-App.app/Watch/Sensor-App-Watch.app. (ID: a037e632-4c6b-4337-b00a-0625e73922f4) Unfortunately I don't know which other team registered it with their account because the source code was open source but I didn't collaborate with others on it. Is it not possible for apple to delete it from the other team if it was registered due to a bug?
3w
Reply to How to delete in CoreData in an MacOS SwiftUI application (.onDelete is not working)
.onDelete is working fine on the mac when swiping from right to left with magic mouse or trackpad. But i prefer to use a context menu and add the delete function there. var body: some View {         List {             ForEach(items) { item in                 Text("Item at \(item.timestamp!, formatter: itemFormatter)")                     .contextMenu(ContextMenu(menuItems: {                         Button(action: {                             viewContext.delete(item)                             do {                                 try viewContext.save()                             } catch {                                 let nsError = error as NSError                                 fatalError("Unresolved error \(nsError), \(nsError.userInfo)")                             }                         }, label: {                             Text("Delete")                         })                     }))             }             .onDelete(perform: deleteItems)         }         .toolbar {             #if os(iOS)             EditButton()             #endif             Button(action: addItem) {                 Label("Add Item", systemImage: "plus")             }         }     }
May ’21
Reply to Core Data and SwiftUI in Xcode 12
Just create your own Core Data class and attach it to your app. import SwiftUI import CoreData @main struct TestApp: App { 		let context = PersistentCloudKitContainer.persistentContainer.viewContext 		var body: some Scene { 				WindowGroup { 						ContentView().environment(\.managedObjectContext, context) 				} 		} } And the custom class 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: "Model") 				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)") 						} 				} 		} }
Jun ’20
Reply to SwiftUI App lifecycle
With ScenePhase you can access the different states of the app as done previously in SceneDelegate @main struct TestApp: App {     var body: some Scene {         WindowGroup {             ContentView()         }         .onChange(of: scenePhase) { phase in             switch phase {             case .active:             print("Active")             case .inactive:                 print("Inactive")             case .background:                 print("Background")             @unknown default:                 print("Unknown")             }         }     } }
Jun ’20
Reply to Is there a way to use Core Data/CloudKit to store and move data with Swift UI in Xcode 12?
You can create your custom PersistentCloudKitContainer Class. One thing I was still struggling with was to apply the Merge Policies. I couldn't figure out how this works. Thats why they are commented out in my code below. import SwiftUI import CoreData @main struct TestApp: App {     let context = PersistentCloudKitContainer.persistentContainer.viewContext     //context.automaticallyMergesChangesFromParent = true     //context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy     var body: some Scene {         WindowGroup {             ContentView().environment(\.managedObjectContext, context)         }     } } And my Custom Class 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: "Model")         container.loadPersistentStores(completionHandler: { (storeDescription, error) in             if let error = error as NSError? {                 fatalError("Unresolved error \(error), \(error.userInfo)")             }         })         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)")             }         }     } }
Jun ’20
Reply to Core Data and SwiftUI in Xcode 12
You need to create a custom Core Data class and inject it into ContentView() I don‘t have a default file at hand but you can inject it like below let context = PersistentCloudKitContainer.persistentContainer.viewContext 		 ContentView().environment(\.managedObjectContext, context) Below my CloudKitContainer but you can simply change that to a regular PersistentContainer class 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: NSPersistentCloudKitContainer = { 		 				let container = NSPersistentCloudKitContainer(name: "Container_Name") 				container.loadPersistentStores(completionHandler: { (storeDescription, error) in 						if let error = error as NSError? { 							 								fatalError("Unresolved error \(error), \(error.userInfo)") 						} 				}) 				 		// 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)") 						} 				} 		} }
Jun ’20