I am engaged on an unbiased watchOS app and I used to be on the lookout for the very best answer to persist information domestically and have a web-based sync with the iCloud storage.
I’ve discovered in regards to the SwiftData which is working very nicely for my app. Then I wished to hook up the info to the iCloud containers so I picked up the CloudKit. I am testing the method with a TestFlight builds for my watchOS app however I can’t see any data being saved within the iCloud container.
I attempted working the identical configuration and similar sort for a clear iOS app simply to check the syncing system. It is working with no downside. I can see the info uploaded (in iCloud container) from an iOS in addition to within the iOS app whereas making a document from the CloudKit Console. Sadly it isn’t the case for my watchOS app.
@Mannequin
last class Merchandise {
var timestamp: Date = Date()
init(timestamp: Date) {
self.timestamp = timestamp
}
}
@major
struct TestApp: App {
var sharedModelContainer: ModelContainer = {
let schema = Schema([
Item.self,
])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
do {
return strive ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Couldn't create ModelContainer: (error)")
}
}()
var physique: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(sharedModelContainer)
}
}
struct ContentView: View {
@Setting(.modelContext) non-public var modelContext
@Question non-public var gadgets: [Item]
var physique: some View {
NavigationSplitView {
Checklist {
ForEach(gadgets) { merchandise in
NavigationLink {
Textual content("Merchandise at (merchandise.timestamp, format: Date.FormatStyle(date: .numeric, time: .commonplace))")
} label: {
Textual content(merchandise.timestamp, format: Date.FormatStyle(date: .numeric, time: .commonplace))
}
}
.onDelete(carry out: deleteItems)
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(motion: addItem) {
Label("Add Merchandise", systemImage: "plus")
}
}
}
} element: {
Textual content("Choose an merchandise")
}
}
non-public func addItem() {
withAnimation {
let newItem = Merchandise(timestamp: Date())
modelContext.insert(newItem)
}
}
non-public func deleteItems(offsets: IndexSet) {
withAnimation {
for index in offsets {
modelContext.delete(gadgets[index])
}
}
}
}
Code above is principally an instance offered by the Xcode for an app utilizing CloudKit and it is working very nicely for the iOS app.
I’ve added the potential to:
- Background Modes: Distant notifications
- iCloud: CloudKit + added a container
- Push notifications
Did I miss one thing whereas configuring the setup? I figured that if Apple gives SwiftData and CloudKit that it could look the identical between the platforms by way of a logic. I can’t discover something extra to setup the SwiftData + CloudKit for an unbiased watchOS app.