Thanks for all your support. I really hope this can somehow get resolved as it‘s a very strange issue
Post
Replies
Boosts
Views
Activity
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?
I have this app open source on Github. Thats a good hint. Maybe it was a mistake to do so. But ultimately i should be the first using this bundle id as my app is already in App Store. So i guess it should be tied to my team in the first place and nobody else should be able to register it.
I wasn't sure if it's a good idea to publish the bundle identifier in the forum. I created a support request with more details to the app. (Case-ID: 9822686)
.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")
}
}
}
If you want to hardcode the setting for Satellite you can simply add the following code in line 29 of your example
uiView.mapType = .satellite
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)")
						}
				}
		}
}
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")
}
}
}
}
It's still possible to use CoreData with SwiftUI
Related questions have been answered already here:
https://developer.apple.com/forums/thread/650173
and here:
https://developer.apple.com/forums/thread/649860
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)")
}
}
}
}
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)")
						}
				}
		}
}