I have a SwiftUI + SwiftData (with iCloud) app. The setup code is standard, with schema migrations (mostly lightweight, one custom). Everything works correctly except in one scenario.
When I run a newer version of the app (with an updated schema adding one field + migration) on a device with the previous data container (the usual app version update through TestFlight), I encounter an issue on the first launch. The app crashes on the first "cold" start but runs successfully on subsequent launches.
The error I receive on the first run is:
addPersistentStoreWithType:configuration:URL:options:error: returned error NSCocoaErrorDomain (134060)
NSLocalizedFailureReason : Unable to find a configuration named 'default' in the specified managed object model.
What might be a problem and how to resolve it?
iCloud & Data
RSS for tagLearn how to integrate your app with iCloud and data frameworks for effective data storage
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello everyone,
I'm currently working on an iOS app using SwiftUI and Core Data, integrating CloudKit for data synchronization. I've set up my Core Data stack with NSPersistentCloudKitContainer, and everything appears to be working correctly locally. However, I'm not seeing any records appearing in the CloudKit Dashboard. This issue started occurring after transferring the Apple Developer account ownership and changing the CloudKit container.
Here's a summary of my setup and what I've tried so far:
Setup
PersistenceController.swift
import SwiftUI
import Foundation
import CoreData
import CloudKit
class PersistenceController {
static let shared = PersistenceController()
let container: NSPersistentCloudKitContainer
init() {
container = NSPersistentCloudKitContainer(name: "Model")
guard let description = container.persistentStoreDescriptions.first else {
fatalError("No Descriptions found")
}
description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.com.company.Project")
container.loadPersistentStores { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
}
container.viewContext.automaticallyMergesChangesFromParent = true
}
func saveContext() {
let context = container.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
static let preview: PersistenceController = {
let controller = PersistenceController()
// Remove existing preview data
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = Letter.fetchRequest()
let batchDeleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
let userFetchRequest: NSFetchRequest<NSFetchRequestResult> = User.fetchRequest()
let userBatchDeleteRequest = NSBatchDeleteRequest(fetchRequest: userFetchRequest)
let senderFetchRequest: NSFetchRequest<NSFetchRequestResult> = Sender.fetchRequest()
let senderBatchDeleteRequest = NSBatchDeleteRequest(fetchRequest: senderFetchRequest)
do {
try controller.container.viewContext.execute(batchDeleteRequest)
try controller.container.viewContext.execute(userBatchDeleteRequest)
try controller.container.viewContext.execute(senderBatchDeleteRequest)
try controller.container.viewContext.save()
} catch {
fatalError("Failed to delete preview data: \(error)")
}
}
Entitlements.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.com.company.Project</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudKit</string>
</array>
</dict>
</plist>
What I've Tried
Verified that the iCloud capability is enabled in the Xcode project settings.
Checked the containerIdentifier in the NSPersistentCloudKitContainer setup.
Ensured the app is signed in with the correct iCloud account.
Observed that local Core Data operations work correctly and save without errors.
Waited to ensure any potential synchronization delays are accounted for.
Observations
I see debug messages in the Xcode console indicating that records are being serialized and saved to CloudKit, but they do not appear in the CloudKit Dashboard.
I have verified that I'm looking at the correct Private Database and _defaultZone.
When I delete the app and reinstall it, I can see that the data remains, indicating that the data is being stored somewhere in iCloud but not visible in the CloudKit Dashboard.
After resetting the schema in the CloudKit Console and running the app, the schema (including record types) syncs immediately, but the records are still not visible.
Console Output
CoreData: debug: CoreData+CloudKit: -[PFCloudKitSerializer newCKRecordsFromObject:fullyMaterializeRecords:includeRelationships:error:](576): Serializer has finished creating record: <CKRecord: 0x15b13e600; recordType=CD_Letter, recordID=F879D7B8-0338-418D-A330-6B9DF7947C6A:(com.apple.coredata.cloudkit.zone:__defaultOwner__), values={
"CD_content" = "Dear User. Happy Valentine's Day! Today. l want to remind you of how much you mean to me. Your presence in my life fills my heart with joy and love. Thank you for being my confidant, my friend, and my love. Every moment with you is precious, and I look forward to creating many more beautiful memories together. With all my love, Thomas";
"CD_createdAt" = "2024-07-30 03:17:13 +0000";
"CD_date" = "2024-07-30 03:15:58 +0000";
"CD_emotion" = Lovely;
"CD_entityName" = Letter;
"CD_icon" = "❤️🔥";
"CD_id" = "81569A99-E74C-43AF-B346-220A75EA336E";
"CD_imageData" = "{ length=282816, sha256=a76343766534e061472e243deec7f0b428c85e8a6b94e6cd761443c45f5be41c }";
"CD_primaryAlpha" = "0.4313725490196079";
"CD_primaryBlue" = 0;
"CD_primaryGreen" = "0.09014883061658401";
"CD_primaryRed" = "0.4156862745098039";
"CD_secondaryAlpha" = 1;
"CD_secondaryBlue" = "0.8823529411764706";
"CD_secondaryGreen" = "0.8784313725490196";
"CD_secondaryRed" = "0.9490196078431372";
"CD_sender" = "EF893D7E-E9E9-453B-B76E-6A5D77E14AA3";
"CD_tertiaryAlpha" = 1;
"CD_tertiaryBlue" = "0.8823529411764706";
"CD_tertiaryGreen" = "0.8784313725490196";
"CD_tertiaryRed" = "0.9490196078431372";
"CD_title" = "I love you";
}>
Despite this, no records are found in the CloudKit Dashboard.
Request for Assistance
Are there any additional steps I might have missed to ensure that records sync correctly with CloudKit?
Could there be any known issues or additional configurations required for syncing Core Data with CloudKit?
Any advice on further troubleshooting steps or areas to investigate would be greatly appreciated.
Thank you for your time and assistance!
Hi! I'm building an app from production Xcode_15.4.0 and I'm seeing strange behavior from the Model macro:
import SwiftData
@Model package class Person {
init() {
}
}
Building this from Xcode_15.4.0 or Swift 5.10 leads to these errors:
/var/folders/1j/0r1s_v0n4bn200kt9nkm9j5w0000gn/T/swift-generated-sources/@__swiftmacro_9MyLibrary6Person5ModelfMe_.swift:1:1: error: initializer 'init(backingData:)' must be as accessible as its enclosing type because it matches a requirement in protocol 'PersistentModel'
extension Person: SwiftData.PersistentModel {
^
/Users/rick/Desktop/MyLibrary/Sources/MyLibrary/MyLibrary.swift:3:1: note: in expansion of macro 'Model' on class 'Person' here
@Model package class Person {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/1j/0r1s_v0n4bn200kt9nkm9j5w0000gn/T/swift-generated-sources/@__swiftmacro_9MyLibrary6Person5ModelfMm_.swift:19:10: note: mark the initializer as 'package' to satisfy the requirement
required init(backingData: any SwiftData.BackingData<Person>) {
^
/Users/rick/Desktop/MyLibrary/Sources/MyLibrary/MyLibrary.swift:3:1: note: in expansion of macro 'Model' on class 'Person' here
@Model package class Person {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/1j/0r1s_v0n4bn200kt9nkm9j5w0000gn/T/swift-generated-sources/@__swiftmacro_9MyLibrary6Person5ModelfMe_.swift:1:1: error: property 'schemaMetadata' must be as accessible as its enclosing type because it matches a requirement in protocol 'PersistentModel'
extension Person: SwiftData.PersistentModel {
^
/Users/rick/Desktop/MyLibrary/Sources/MyLibrary/MyLibrary.swift:3:1: note: in expansion of macro 'Model' on class 'Person' here
@Model package class Person {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/1j/0r1s_v0n4bn200kt9nkm9j5w0000gn/T/swift-generated-sources/@__swiftmacro_9MyLibrary6Person5ModelfMm_.swift:13:12: note: mark the static property as 'package' to satisfy the requirement
static var schemaMetadata: [SwiftData.Schema.PropertyMetadata] {
^
/Users/rick/Desktop/MyLibrary/Sources/MyLibrary/MyLibrary.swift:3:1: note: in expansion of macro 'Model' on class 'Person' here
@Model package class Person {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/1j/0r1s_v0n4bn200kt9nkm9j5w0000gn/T/swift-generated-sources/@__swiftmacro_9MyLibrary6Person5ModelfMe_.swift:1:1: error: initializer 'init(backingData:)' must be as accessible as its enclosing type because it matches a requirement in protocol 'PersistentModel'
extension Person: SwiftData.PersistentModel {
^
/Users/rick/Desktop/MyLibrary/Sources/MyLibrary/MyLibrary.swift:3:1: note: in expansion of macro 'Model' on class 'Person' here
@Model package class Person {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/1j/0r1s_v0n4bn200kt9nkm9j5w0000gn/T/swift-generated-sources/@__swiftmacro_9MyLibrary6Person5ModelfMm_.swift:19:10: note: mark the initializer as 'package' to satisfy the requirement
required init(backingData: any SwiftData.BackingData<Person>) {
^
/Users/rick/Desktop/MyLibrary/Sources/MyLibrary/MyLibrary.swift:3:1: note: in expansion of macro 'Model' on class 'Person' here
@Model package class Person {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/1j/0r1s_v0n4bn200kt9nkm9j5w0000gn/T/swift-generated-sources/@__swiftmacro_9MyLibrary6Person5ModelfMe_.swift:1:1: error: property 'schemaMetadata' must be as accessible as its enclosing type because it matches a requirement in protocol 'PersistentModel'
extension Person: SwiftData.PersistentModel {
^
/Users/rick/Desktop/MyLibrary/Sources/MyLibrary/MyLibrary.swift:3:1: note: in expansion of macro 'Model' on class 'Person' here
@Model package class Person {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/1j/0r1s_v0n4bn200kt9nkm9j5w0000gn/T/swift-generated-sources/@__swiftmacro_9MyLibrary6Person5ModelfMm_.swift:13:12: note: mark the static property as 'package' to satisfy the requirement
static var schemaMetadata: [SwiftData.Schema.PropertyMetadata] {
^
/Users/rick/Desktop/MyLibrary/Sources/MyLibrary/MyLibrary.swift:3:1: note: in expansion of macro 'Model' on class 'Person' here
@Model package class Person {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: fatalError
Building from Xcode_16_beta_4 or Swift 6.0 builds with no errors.
Is this package issue being tracked for SwiftData when building from 5.10? It looks like this is fixed from 6.0… but I would like to build this code from production Swift today.
Potential workarounds:
Mark the class as internal or public?
Use Xcode to inline the macro expansion and directly modify the broken functions with the correct access control?
Any more ideas?
My preference would be to keep this type package (while also building from 5.10). Any more workarounds (other than expanding the macro and modifying the functions myself by-hand)? Thanks!
Hi! I'm running into some confusing behavior when attempting to delete all instance of one model type from a ModelContext. My problem is specifically using the delete(model:where:includeSubclasses:)^1 function (and passing in a model type). I seem to be running into situations where this function fails silently without throwing an error (no models are deleted).
I am seeing this same behavior from Xcode_15.4.0 and Xcode_16_beta_4.
I start with a model:
@Model final public class Item {
var timestamp: Date
public init(timestamp: Date = .now) {
self.timestamp = timestamp
}
}
Here is an example of a Store class that wraps a ModelContext:
final public class Store {
public let modelContext: ModelContext
public init(modelContainer: SwiftData.ModelContainer) {
self.modelContext = ModelContext(modelContainer)
}
}
extension Store {
private convenience init(
schema: Schema,
configuration: ModelConfiguration
) throws {
let container = try ModelContainer(
for: schema,
configurations: configuration
)
self.init(modelContainer: container)
}
}
extension Store {
public convenience init(url: URL) throws {
let schema = Schema(Self.models)
let configuration = ModelConfiguration(url: url)
try self.init(
schema: schema,
configuration: configuration
)
}
}
extension Store {
public convenience init(isStoredInMemoryOnly: Bool = false) throws {
let schema = Schema(Self.models)
let configuration = ModelConfiguration(isStoredInMemoryOnly: isStoredInMemoryOnly)
try self.init(
schema: schema,
configuration: configuration
)
}
}
extension Store {
public func fetch<T>(_ type: T.Type) throws -> Array<T> where T : PersistentModel {
try self.modelContext.fetch(
FetchDescriptor<T>()
)
}
}
extension Store {
public func fetchCount<T>(_ type: T.Type) throws -> Int where T : PersistentModel {
try self.modelContext.fetchCount(
FetchDescriptor<T>()
)
}
}
extension Store {
public func insert<T>(_ model: T) where T : PersistentModel {
self.modelContext.insert(model)
}
}
extension Store {
public func delete<T>(model: T.Type) throws where T : PersistentModel {
try self.modelContext.delete(model: model)
}
}
extension Store {
public func deleteWithIteration<T>(model: T.Type) throws where T : PersistentModel {
for model in try self.fetch(model) {
self.modelContext.delete(model)
}
}
}
extension Store {
private static var models: Array<any PersistentModel.Type> {
[Item.self]
}
}
That should be pretty simple… I can use this Store to read and write Item instances to a ModelContext.
Here is an example of an executable that shows off the unexpected behavior:
func main() async throws {
do {
let store = try Store(isStoredInMemoryOnly: true)
store.insert(Item())
print(try store.fetchCount(Item.self) == 1)
try store.delete(model: Item.self)
print(try store.fetchCount(Item.self) == 0)
}
do {
let store = try Store(isStoredInMemoryOnly: true)
store.insert(Item())
print(try store.fetchCount(Item.self) == 1)
try store.deleteWithIteration(model: Item.self)
print(try store.fetchCount(Item.self) == 0)
}
do {
let store = try StoreActor(isStoredInMemoryOnly: true)
await store.insert(Item())
print(try await store.fetchCount(Item.self) == 1)
try await store.delete(model: Item.self)
print(try await store.fetchCount(Item.self) == 0)
}
do {
let store = try StoreActor(isStoredInMemoryOnly: true)
await store.insert(Item())
print(try await store.fetchCount(Item.self) == 1)
try await store.deleteWithIteration(model: Item.self)
print(try await store.fetchCount(Item.self) == 0)
}
}
try await main()
My first step is to set up an executable with an info.plist to support SwiftData.^2
My expectation is all these print statements should be true. What actually happens is that the calls to delete(model:where:includeSubclasses:) seem to not be deleting any models (and also seem to not be throwing errors).
I also have the option to test this behavior with XCTest. I see the same unexpected behavior:
import XCTest
final class StoreXCTests : XCTestCase {
func testDelete() throws {
let store = try Store(isStoredInMemoryOnly: true)
store.insert(Item())
XCTAssert(try store.fetchCount(Item.self) == 1)
try store.delete(model: Item.self)
XCTAssert(try store.fetchCount(Item.self) == 0)
}
func testDeleteWithIteration() throws {
let store = try Store(isStoredInMemoryOnly: true)
store.insert(Item())
XCTAssert(try store.fetchCount(Item.self) == 1)
try store.deleteWithIteration(model: Item.self)
XCTAssert(try store.fetchCount(Item.self) == 0)
}
}
Those tests fail… implying that the delete(model:where:includeSubclasses:) is not actually deleting any models.
FWIW… I see the same behavior (from command-line and XCTest) when my Store conforms to ModelActor.^3 ^4
This does not seem to be the behavior I am seeing from using the delete(model:where:includeSubclasses:) in a SwiftUI app.^5 Calling the delete(model:where:includeSubclasses:) function from SwiftUI does delete all the model instances.
The SwiftUI app uses a ModelContext directly (without a Store type). I can trying writing unit tests directly against ModelContext and I see the same behavior as before (no model instances are being deleted).^6
Any ideas about that? Is this a known issue with SwiftData that is being tracked? Is the delete(model:where:includeSubclasses:) known to be "flaky" when called from outside SwiftUI? Is there anything about the way these ModelContext instance are being created that we think is leading to this unexpected behavior?
For a photo based social media network (think instagram), which cloud platform would be best from the point of not costing even with scale?
See I was attracted to cloudkit because as the user count increases, so does the free allowed storage. Compared to say Supabase which gives literally 1GB of file storage on the free plan, which would get used up very quickly as more and more users upload photos.
Very interested to hear thoughts on choosing the right platform. (Keep in mind only interested in developing an iOS app and not worried about cross platform compatibility).
Hi everyone,
Have anybody faced with Core Data issues, trying to migrate the project to Xcode16 beta 4?
We are using transformableAttributeType in some entities, with attributeValueClassName = "[String]" and valueTransformerName = "NSSecureUnarchiveFromData". It is working just fine for years, but now I am trying to run the project from Xcode16 and have 2 issues:
in Xcode logs I see warning and error:
CoreData: fault: Declared Objective-C type "[String]" for attribute named alertBarChannels is not valid
CoreData: Declared Objective-C type "[String]" for attribute named alertBarChannels is not valid
periodically the app crashes when we are assigning value to this attribute, with error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds'
Once again, in Xcode 15 it works fine, and it was working for years.
Cannot find any information about what was changed in the framework...
Thank you in advance for any information, which could clarify what is going on.
I am able to fetch CloudKit records from my MacOS command line tool/daemon.
However, I would like CloudKit to notify my daemon whenever CKRecords were altered so I would not have to poll periodically.
In CloudKit console I see that my app successfully created CloudKit subscription, but the part that confuses me is where in my app do I define callback function that gets called whenever CloudKit attempted to notify my app of CloudKit changes?
My first question - do I need to define callback in my implementation of UNUserNotificationCenterDelegate? NSApplicationDelegate? Something else?
My second question, would CKSyncEngine work from command line application?
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
CloudKit
Command Line Tools
Service Management
This just started happening when installing my app on my phone and ipad. It still seems to work and the errors go away on the second installation, but it doesn't strike me as good.
The app has not been released yet.
When I remove the AppGroup, the error disappears. But I have a widget, so I need the AppGroup.
I've cleaned the build, deleted derived files, and rebooted many times.
I've deleted the app on the device and rebooted the device many times.
I've deleted the AppGroup in iCloud and then recreated it. I was really hoping that would work, but nope. I've created a new App Group and that didn't make a difference either.
So I'm stumped. Any thoughts on how to fix this?
thanks
CoreData: error: Failed to stat path '/private/var/mobile/Containers/Shared/AppGroup/2602E28B-089C-4011-BA09-19D11183E4F7/Library/Application Support/default.store', errno 2 / No such file or directory.
CoreData: error: Executing as effective user 501
CoreData: error: Failed to statfs file; errno 2 / No such file or directory.
CoreData: error: Logging status information for directory path: /private/var/mobile/Containers/Shared/AppGroup/2602E28B-089C-4011-BA09-19D11183E4F7/Library/Application Support
CoreData: error: Executing as effective user 501
....
error: URL: file:///private/var/mobile/Containers/Shared/AppGroup/2602E28B-089C-4011-BA09-19D11183E4F7/Library/Application%20Support/default.store
error: <NSPersistentStoreCoordinator: 0x300a3e610>: Attempting recovery from error encountered during addPersistentStore: 0x302f5f510 Error Domain=NSCocoaErrorDomain Code=512 "The file couldn’t be saved." UserInfo={reason=Failed to create file; code = 2}
error: During recovery, parent directory path reported as missing
error: Recovery attempt while adding <NSPersistentStoreDescription: 0x302f5f510> (type: SQLite, url: file:///private/var/mobile/Containers/Shared/AppGroup/2602E28B-089C-4011-BA09-19D11183E4F7/Library/Application%20Support/default.store) was successful!
CloudKit sync is very unstable. Sometimes it just stops syncing for no reason, other times it works almost instantly.
The core issue with synchronization is that CoreData relies mostly on two things:
silent push notifications, which are by design unreliable and can be throttled
user interactions, I noticed that the local database is updated most likely periodically and also based on some app events like entering the foreground.
Unfortunately, there is no SDK function that allows us to force sync with CloudKit, which basically prevents us from providing some features to recover if a user encounters problems.
After thousands of tests, I finally discovered what was wrong and how to make the synchronization stable. Basically, I noticed that at some point CoreData decides that it won't synchronize data unless you deactivate and activate the application, which is crazy. It's getting even worse if we talk about extensions like the keyboard extension on iOS. The same happens on all platforms.
Therefore, knowing that I implemented a trick that happened to work perfectly. The workaround requires to periodically sending an event pretending that the app is going foreground.
macOS:
var cancellable = Set<AnyCancellable>()
// ...
Timer.publish(every: 20.0, on: RunLoop.main, in: .common)
.autoconnect()
.sink { _ in
NotificationCenter.default.post(.init(name: NSApplication.willBecomeActiveNotification))
}
.store(in: &cancellable)
iOS:
var cancellable = Set<AnyCancellable>()
// ...
Timer.publish(every: 20.0, on: RunLoop.main, in: .common)
.autoconnect()
.sink { _ in
NotificationCenter.default.post(.init(name: UIApplication.didBecomeActiveNotification))
}
.store(in: &cancellable)
After that, everything works perfectly. Pitty that the solution mostly meant for enterprise is so unstable and there is not even a single SDK function to recover from that (force sync).
Any plans to fix CoreData+CloudKit? I also created a ticket: #FB14531806.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
CloudKit
Cloud and Local Storage
Core Data
I begin testing my IOS swiftdats Xcode 15 swift 5 on Sonoma and I am able to create my siwftdata tables as well as add records to several of the tables, Then as I proceeded with my te tables disappear and I get this error in the Xcode debug console:
error: Error: Persistent History (6) has to be truncated due to the following entities being removed: (
AppSettings,
Invoice,
Clientele,
Pay,
InvoiceItem,
TrackingArt
)
This app used to work fine and as I was making changes it started behaving in this manner. Beside the code I will supply the entire debug console with the attached file
debugConsole.txt
Here is how I have the swift data containers setup.
import SwiftData
import TipKit
import CloudKit
@main
struct ArtManagerApp: App {
@StateObject private var copyInvoiceDetails = CopyInvoiceDetails()
@StateObject private var copyPaymentDetails = CopyPaymentDetails()
@StateObject private var artTypeSettings = ArtTypeSettings()
@StateObject private var tipManager = TipManager()
// @Query(sort: \ArtPiece.artPieceID, order: .forward) private var artPieces: [ArtPiece]
// @Query(sort: \AppSettings.setID, order: .reverse) private var settingsList: [AppSettings]
var sharedModelContainer: ModelContainer = {
let schema = Schema([
ArtPiece.self, Clientele.self, TrackingArt.self, Invoice.self, InvoiceItem.self, AppSettings.self, Pay.self
])
let modelConfiguration = ModelConfiguration(schema: schema,
isStoredInMemoryOnly: false)
do {
return try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")
}
}()
var body: some Scene {
WindowGroup {
ContentView()
.navigationTitle("🎨 Art Manager")
.environmentObject(artTypeSettings)
.environmentObject(copyInvoiceDetails)
.environmentObject(copyPaymentDetails)
.environmentObject(tipManager) // Pass it to the ContentView
.modelContainer(sharedModelContainer)
}
}
}
class TipManager: ObservableObject {
@Published var tips: [ArtManagerTip] = []
init() {
loadTips()
}
func loadTips() {
tips = [ArtManagerTips.search_tip, ArtManagerTips.delete_tip, ArtManagerTips.extendedSearch_tip,
ArtManagerTips.searchPayments_tip, ArtManagerTips.searchArt_tip, ArtManagerTips.librarySearch_tip, ArtManagerTips.artMaintenanceSearch_tip]
}
}
class CopyPaymentDetails: ObservableObject {
@Published var payNumber: Int32 = 0
@Published var payType: String = ""
@Published var payPatronID: Int32 = 0
@Published var payPatronName: String = ""
@Published var payPatronAddress: String = ""
@Published var payPaymentAmount: Double = 0.0
@Published var payDatePayed: Date = Date()
}
class CopyInvoiceDetails: ObservableObject {
@Published var invoiceNumber: Int32 = 0
@Published var invoicePatronName: String = ""
@Published var invoicePatronPO: String = ""
@Published var invoiceDateCreated: Date = Date()
@Published var artPieceIDSaved: [Int32] = []
}
I wonder why that happens.
When opened on Mac.
Acceptance of files with the '.hwp' extension is applied. But not on ipad
I'd like to know why, where can I get information?
here is the code
<!DOCTYPE html>
<html>
<body>
<h1>The input accept attribute</h1>
<form action="/action_page.php">
<label for="img">Select file:</label>
<input type="file" accept=".pdf, .hwp">
</form>
</body>
</html>
Apparently the @Query property wrapper from SwiftData does not update when data is loaded from CloudKit. The data can be programmatically be accessed but nothing appears in the view.
Steps to reproduce:
Create new Xcode project using the SwiftData storage option.
Provide a default value for the Item Model. That is required so data can be automatically synced by SwiftData.
Enable iCloud -> CloudKit capabilities and choose a container
Enable Background Modes -> Remote notification capability
Add a toolbar button that prints the number of items from @Query like this:
ToolbarItem {
Button {
print(items.count)
} label: {
Label("Count", systemImage: "1.circle")
}
}
Install app on a physical device that can sync to iCloud.
Add some items using the + in the toolbar
Delete app and wait for around a minute
Reinstall app with a debugger attached
Press the 1.circle button in the toolbar. It will print either 0 or the number of items you previously added. When it does not print 0 the data should be visible but it is not. Once you quit and relaunch the app or press the + button again, all of the items appear.
Has anyone else experienced this before? Anything I can do so the data appears / the view reloads once the items are available? I need to update my view once the data has been loaded from iCloud.
I already filed a bug report with id FB14619787.
I'm just starting to learn iOS app development and I'm currently using SwiftData. The main app is working fine, and now I've added a Widget to use data from the main app. I've already enabled App Groups and want to reference the shared model entities from the main app, but I'm getting an error saying "can't find type in scope." What additional configurations do I need to make in order to properly reference the same entities? I've seen many example codes that have a "Shared" folder, but even after creating one and moving the files into it, I'm still unable to use them properly. I must be missing some configuration, right?
Also, there's another issue: when debugging the Widget, I keep getting the following error. What could be causing this?
SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'XXXX-Widget' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed."
Hi,
I know how to sort SwiftData records based on one of its properties such as name, but how to sort based on recent updated records ? like in Apple Notes App ?
Kind Regards
I am trying to use the ModelContainer's "delete" function to delete all instances of a model but I'm getting an error related to my relationships:
Constraint trigger violation: Batch delete failed due to mandatory OTO nullify inverse on LeagueSeasonRanking/golfer
I do have a relationship on Golfer, a toMany relationship to LeagueSeasonRanking which is marked with a cascade delete rule... I would expect that to take care of things and cascade along but it seems to not work. Is that a bug?
Some of my models have many-to-many relationships. For example, when I add a file to a directory, a model is created from that in addition to any relationships it may contain.
I’ve incorporated SwiftData History into my front end and backend projects and it’s able to show me what has been inserted, updated, and even deleted after the file is removed from the directory. Which only returns the identifiers I’ve set to become tombstone values. All working as expected and my client can now sync with the server.
I can add and remove the same file repeatedly and I’m able to retrieve all the transactions.
However if I add another file and then fetch transactions, it crashes at .fetchHistory(_:). The errors say they cannot find the property of a model it has a many-to-many relationship with.
I omitted appending any relationships, but the errors start pointing to properties belonging to the model itself.
I’ve only managed to get this functioning by setting the @Relationship macro to a single model. Previously, I had this macro with its delete rule and inverse on other types. But doing so would crash the same way immediately and wouldn’t let me fetch history at all.
Since it crashes at fetching the history, I’m unable to proceed and the options appear to be limited for what I can do before I fetch them.
Does SwiftData History not work with many-to-many relationships or is this a bug?
Hello,
I'm using NSPersistentCloudKitContainer. If the user disables iCloud sync for my app in the system settings and opens the app, all records are immediately wiped out, even if there are unsynced changes (like records added offline).
Disabling iCloud sync doesn't even show any warning, so the user may lose all data (if it's not already synced to Cloud).
Is it possible to intercept that the store will be wiped out when the app is launching? I would copy all records to the local storage then to avoid losing data by the user.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
CloudKit
Cloud and Local Storage
Core Data
What is the recommended way of intercepting and processing errors?
As far as I know, there are 4 main areas:
iCloud account status - this can be checked and intercepted via notifications
exceptions from fetch/execute/save - it can be a simple do..catch, but what exceptions can we expect here, what should be handled, and how?
there could be some asynchronous issues with synchronization. How should we intercept them and how should they be handled?
issues with iCloud storage - quota exceeded, etc. How to intercept & handle those?
I'm trying to achieve production-ready implementation, but there are many pitfalls and hidden issues that are not well documented. Could you provide some advice on how to handle properly all these situations?
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
CloudKit
Cloud and Local Storage
Core Data
Hello!
I apologize in advance if I chose the wrong topic for my question, this is my first time on this forum.
I am a novice developer and I am creating an application. I use Swift + SwiftUI, but I ran into such a problem that I have nowhere to store my data and I do not know how to store it correctly. I know that there is a SwiftData framework that is used to work with data, but I don't understand the documentation.
Please be understanding. How do I start learning SwiftData? What topics should be studied? What is the order of studying topics? Thank you all in advance!
Is there any version of UICloudSharingController available on macOS or do we need to handle it manually?
How to manually configure a share and send an invitation from macOS?
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
CloudKit
Cloud and Local Storage
Core Data