Post

Replies

Boosts

Views

Activity

Random "duplicate column name" crashes using SwiftData
Hello everyone, I am experiencing a very weird issue. I have a simple relationship between 2 models, that occasionally starts crashing the app, with the following error: error: <NSPersistentStoreCoordinator: 0x28007f6b0>: Attempting recovery from error encountered during addPersistentStore: 0x282523c60 Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///private/var/mobile/Containers/Shared/AppGroup/F8286D67-AC8C-4441-A151-13B5AAA509F3/Library/Application%20Support/default.store, reason=Cannot migrate store in-place: I/O error for database at /private/var/mobile/Containers/Shared/AppGroup/F8286D67-AC8C-4441-A151-13B5AAA509F3/Library/Application Support/default.store. SQLite error code:1, 'duplicate column name: Z1POSITIONS', destinationURL=file:///private/var/mobile/Containers/Shared/AppGroup/F8286D67-AC8C-4441-A151-13B5AAA509F3/Library/Application%20Support/default.store, NSUnderlyingError=0x2825c6700 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={NSSQLiteErrorDomain=1, NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/F8286D67-AC8C-4441-A151-13B5AAA509F3/Library/Application Support/default.store, NSUnderlyingException=I/O error for database at /private/var/mobile/Containers/Shared/AppGroup/F8286D67-AC8C-4441-A151-13B5AAA509F3/Library/Application Support/default.store. SQLite error code:1, 'duplicate column name: Z1POSITIONS', reason=I/O error for database at /private/var/mobile/Containers/Shared/AppGroup/F8286D67-AC8C-4441-A151-13B5AAA509F3/Library/Application Support/default.store. SQLite error code:1, 'duplicate column name: Z1POSITIONS'}}} This is particularly weird because the app runs a few times without any code changes, or any CRUD operations in the database, and then suddenly starts throwing exceptions. These are my models: @Model final class Desk { @Attribute(.unique) let id: UUID let name: String? @Relationship(deleteRule: .cascade) var positions: [DeskPosition] = [] init(id: UUID, name: String?) { self.id = id self.name = name } } @Model final class DeskPosition { let id: UUID var title: String private var heightInCm: Double @Transient var height: DeskHeight { get { DeskHeight(value: heightInCm, unit: .centimeters).localized } set { heightInCm = newValue.converted(to: .centimeters).value } } init(id: UUID, height: DeskHeight, title: String) { self.id = id self.heightInCm = height.converted(to: .centimeters).value self.title = title self.height = height } } And this is my schema and model container (I tried adding both models to the schema, or just adding the parent model, and does not seem to make a difference): private var sharedModelContainer: ModelContainer = { let schema = Schema([Desk.self, DeskPosition.self]) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) do { return try ModelContainer(for: schema, configurations: [modelConfiguration]) } catch { fatalError("Could not create ModelContainer: \(error)") } }() I couldn't find anyone else having this same issue. There must be something obviously simple that I am not looking at. Can anyone help? Thank you!
1
0
564
Oct ’23
How to observe changes to properties of an @Observable from another non-view class?
I have a class A and class B, and both of them are @Observable, and none of them are a view. Class A has an instance of class B. I want to be able to listen to changes in this instance of class B, from my class A. Previously, by using ObservableObject, instead of the @Observable macro, every property that needed to be observable, had to be declared as a Publisher. With this new framework, everything seems to be automatically synthesised, and using a Publisher is no longer required, as all the properties are observable. That being said, how can I have an equivalent using @Observable? Is this new macro only for view-facing classes?
1
1
900
Sep ’23
AppIntent timing out after around 25s. Are there solutions or alternatives?
I am launching an app intent from a widget button tap, which, in turn, executes a task in the background that can take up to 40 seconds. This task fails to execute completely most times, as the time out period is around 25 to 30 seconds. Is there any way to work around the app intent time limit? User feedback is not important, as this interacts with an external physical device, so the user knows the state from looking at said device. I was considering other alternatives for when the task fails to execute completely, like prompting the user to continue the task, but this doesn't seem like a valid solution, as there is no way to do this foreground interfacing from a widget. I am completely stumped with this. This was a problem with the old Intents, and it seems like it's still a problem with the new App Intents. I wish Apple would allow developers to control how much the intent would take to timeout.
0
1
470
Aug ’23