Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

CoreData does not update all relationships properly
I have two entities in CoreData Todo and DaysOfYear and a many to one relationship exists between these two entities. When the user launches the app if for the past 4 days the user has not completed any of the todos I add those todos to the incompleteTodos relationship for each day. Thing is only the first day gets updated in core data while the rest of them do not update. I have tried everything that I could, all to no avail. Core Data simply refuses to store any of the updates I make except for the first day even though context.hasChanges acknowledges that the context has changed. ContentView from where I add IncompleteTodos: Todo.addIncompleteTodo(todo: todo, for: days[idx].date, context: context) Extension Todo:static func addIncompleteTodo(todo: Todo, for day: String, context: NSManagedObjectContext) { let today = DayOfYear.withDate(convertStringToGMTDate(day), context: context) todo.incompleteDay = today today.addToIncompleteTodos(todo) print(context.hasChanges) try? context.save() } E
0
0
391
Sep ’20
SwiftData: Crash when deleting from model, but only in prod
I'm testing my app before releasing to testers, and my app (both macOS and iOS) is crashing when I perform one operation, but only in the production build. I have data that loads from a remote source, and can be periodically updated. There is an option to delete all of that data from the iCloud data store, unless the user has modified a record. Each table has a flag to indicate that (userEdited). Here's the function that is crashing: func deleteCommonData(_ type: T.Type) throws { try modelContext.delete(model: T.self, where: #Predicate { !$0.userEdited }) } Here's one of the calls that results in a crash: try modelManager.deleteCommonData(Link.self) Here's the error from iOS Console: SwiftData/DataUtilities.swift:85: Fatal error: Couldn't find Link. on Link with fields [SwiftData.Schema.PropertyMetadata(name: id, keypath: Link., defaultValue: Optional(54EC6602-CA7C-4EC7-AC06-16E7F2E22DE7), metadata: nil), SwiftData.Schema.PropertyMetadata(name: name, keypath: Link., defaultValue: Optional(), metadata
3
0
136
Oct ’25
Reply to How to rotate image in Apple Watch under swift language
Hi, Thank You for reaching out to the query, below is the code in Apple Watch target The outlet of the image object: - @IBOutlet weak var headingIcon: WKInterfaceImage! func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { HeadingValue = Double(round(1 * newHeading.trueHeading) / 1). let newHeadings = Double(newHeading.trueHeading) // need to place image object here. // but it is not inheriting the transform property as UIImageView inherits in iOS. headingIcon. }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’22
Changing relationship delete rule & CloudKit
Hi, any side effect to be aware of when changing a core data relationship delete rule from Null to Cascade? I NSPersistentCloudKitContainer to handle CloudKit sync in case that's relevant. It doesn't look like any migration is required, and the cloudkit schema doesn't change so it seems there's nothing to do on the cloudkit-side either. However I'd prefer to double check to avoid making false assumptions. I wasn't able to find any documentation on that particular point so if someone can shade some light on how things work under the hood that would be appreciated. Thanks!
0
0
918
Jun ’22
Reply to Using separate device and simulator frameworks
The easiest way is to use an xcconfig file. Setting one of those up for your project / target is out of scope but once you do:This will link your framework. By default it will select MyFramework_ARM but on Simulator builds it will select MyFramework_Sim.OTHER_LD_FLAGS = $(inherited) -Wl,MyFramework_ARM OTHER_LD_FLAGS[sdk=embeddedsimulator*] = $(inherited) -Wl,MyFramework_SimThe other way to do this is with a duplicate target: one for device and one for Simulator but that is much more complicated to maintain.
Sep ’17
SwiftData preview sample code
Hi, re: the SwiftData session Create an app with SwifData (https://developer.apple.com/videos/play/wwdc2023/10154) I noted the mention of generating sample preview data. In CoreData, I had a similar need and this was achieved by creating a shared in-memory context; fairly straight forward. The example given for SwiftData was decorated with @MainActor and then added to the target project, then in the #Preview closure, the modelContainer is amended to point to the preview data. Anyways, my problem is that I'm receiving an error when trying to render the preview in question: main actor-isolated let 'previewContainer' can not be referenced from a non-isolated context I suppose my issue is not having used the MainActor wrapper before and being unclear on what's possibly going wrong here (or if it's not just a me problem). Can anyone help?
6
0
6.1k
Jun ’23
Bug in .onmove for SwiftData models
I modified the default Items example from xcode to include two models, a view with a query and a detail view. On this detail view I cannot properly move all items, only the top two, please see the attached video. Especially strange is that some dragging does work and some does not. It changes with the number of sub-items on a todo. The models are SwiftData and it is have a one-to-many relationship. On the many relationship the problem exists. How should the code be adjusted to make sure all items are draggable? https://imgur.com/a/n1y7iXX Below is all code necessary for the minimal example. I target iOS 17.5 and this shows on both preview, simulator and my iPhone. Models @Model final class ToDo { var timestamp: Date var items: [Item] init(timestamp: Date) { self.timestamp = timestamp self.items = [] } } @Model final class Item { var timestamp: Date var done: Bool init(timestamp: Date, done: Bool) { self.timestamp = timestamp self.done = done } } ItemListView (Here is the problem!) s
2
0
1.2k
May ’24
SwiftData + CloudKit: BGSystemTaskScheduler Code=8
Hi everyone, On macOS 26.4 beta (with Xcode 26.4 beta), I’m seeing the following console messages in a brand new SwiftData + CloudKit template project (no custom logic added, fresh CloudKit container): updateTaskRequest called for a pre-running task com.apple.coredata.cloudkit.activity.export.F9EE783D-7521-4EC2-B42C-9FD1F29BA5C4 updateTaskRequest called for an already running/updated task com.apple.coredata.cloudkit.activity.export.F9EE783D-7521-4EC2-B42C-9FD1F29BA5C4 Error updating background task request: Error Domain=BGSystemTaskSchedulerErrorDomain Code=8 (null) These messages appear: When CloudKit is enabled Occasionally on app launch Often when bringing the app back to the foreground (Cmd-Tab away and back) Even with zero additional SwiftData logic They do not appear when CloudKit is disabled. This behavior is reproducible on a completely new project with a fresh CloudKit container. Questions: What exactly do these messages indicate? Is BGSystemTaskScheduler Code=8 expected in this con
2
0
201
Feb ’26
CoreData does not update all relationships properly
I have two entities in CoreData Todo and DaysOfYear and a many to one relationship exists between these two entities. When the user launches the app if for the past 4 days the user has not completed any of the todos I add those todos to the incompleteTodos relationship for each day. Thing is only the first day gets updated in core data while the rest of them do not update. I have tried everything that I could, all to no avail. Core Data simply refuses to store any of the updates I make except for the first day even though context.hasChanges acknowledges that the context has changed. ContentView from where I add IncompleteTodos: Todo.addIncompleteTodo(todo: todo, for: days[idx].date, context: context) Extension Todo:static func addIncompleteTodo(todo: Todo, for day: String, context: NSManagedObjectContext) { let today = DayOfYear.withDate(convertStringToGMTDate(day), context: context) todo.incompleteDay = today today.addToIncompleteTodos(todo) print(context.hasChanges) try? context.save() } E
Replies
0
Boosts
0
Views
391
Activity
Sep ’20
SwiftData: Crash when deleting from model, but only in prod
I'm testing my app before releasing to testers, and my app (both macOS and iOS) is crashing when I perform one operation, but only in the production build. I have data that loads from a remote source, and can be periodically updated. There is an option to delete all of that data from the iCloud data store, unless the user has modified a record. Each table has a flag to indicate that (userEdited). Here's the function that is crashing: func deleteCommonData(_ type: T.Type) throws { try modelContext.delete(model: T.self, where: #Predicate { !$0.userEdited }) } Here's one of the calls that results in a crash: try modelManager.deleteCommonData(Link.self) Here's the error from iOS Console: SwiftData/DataUtilities.swift:85: Fatal error: Couldn't find Link. on Link with fields [SwiftData.Schema.PropertyMetadata(name: id, keypath: Link., defaultValue: Optional(54EC6602-CA7C-4EC7-AC06-16E7F2E22DE7), metadata: nil), SwiftData.Schema.PropertyMetadata(name: name, keypath: Link., defaultValue: Optional(), metadata
Replies
3
Boosts
0
Views
136
Activity
Oct ’25
Reply to How to rotate image in Apple Watch under swift language
Hi, Thank You for reaching out to the query, below is the code in Apple Watch target The outlet of the image object: - @IBOutlet weak var headingIcon: WKInterfaceImage! func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { HeadingValue = Double(round(1 * newHeading.trueHeading) / 1). let newHeadings = Double(newHeading.trueHeading) // need to place image object here. // but it is not inheriting the transform property as UIImageView inherits in iOS. headingIcon. }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’22
Changing relationship delete rule & CloudKit
Hi, any side effect to be aware of when changing a core data relationship delete rule from Null to Cascade? I NSPersistentCloudKitContainer to handle CloudKit sync in case that's relevant. It doesn't look like any migration is required, and the cloudkit schema doesn't change so it seems there's nothing to do on the cloudkit-side either. However I'd prefer to double check to avoid making false assumptions. I wasn't able to find any documentation on that particular point so if someone can shade some light on how things work under the hood that would be appreciated. Thanks!
Replies
0
Boosts
0
Views
918
Activity
Jun ’22
Reply to Saving data structures
NSArray's writeToFile method looks very enticing. I could make the DerivationLine class inherit from NSObject. But again, it's the recursive part that I'm wondering how to handle.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Feb ’16
Reply to Why can't I make Array<T: Equatable> conform to Equatable?
Thanks, that makes sense (unless somebody has a good explanation for why extensions with constraints cannot have an inheritance/conformance clause, neither now nor in the future) .
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15
Reply to Custom menu actions
Inherits from NSObjectclass AppController: NSObject {}In AppDelegate, create @IBOutlet weak var appController: AppController!connected to an ObjectController in MainMenu.xibTo call appController.someMethod()
Replies
Boosts
Views
Activity
Jul ’19
Is there a migration limitations of SwiftData with CloudKitSync?
In CoreData with CloudKit mirroring, only lightweight migration is allowed to database migration. Heavyweight (custom) migration are not recommended. Are the rules also applied to SwiftData with CloudKit mirroring? (I assume it is true, because cloudkit backend properties are not changed even if SwfitData released)
Replies
0
Boosts
0
Views
940
Activity
Jun ’23
Getting Fatal Error using SwiftData for previews after switching to Xcode 16
I was creating a sample SwiftData project using two models and a one to one relationship. Before upgrading to xcode 16, everything was fine and compiled correctly. After upgrading to xcode 16, I get fatal errors: This model instance was destroyed by calling ModelContext.reset and is no longer usable or
Replies
1
Boosts
0
Views
594
Activity
Sep ’24
Reply to Using separate device and simulator frameworks
The easiest way is to use an xcconfig file. Setting one of those up for your project / target is out of scope but once you do:This will link your framework. By default it will select MyFramework_ARM but on Simulator builds it will select MyFramework_Sim.OTHER_LD_FLAGS = $(inherited) -Wl,MyFramework_ARM OTHER_LD_FLAGS[sdk=embeddedsimulator*] = $(inherited) -Wl,MyFramework_SimThe other way to do this is with a duplicate target: one for device and one for Simulator but that is much more complicated to maintain.
Replies
Boosts
Views
Activity
Sep ’17
Connecting SwiftData to Data Sources other than iCloud
Hi, In this year WWDC 2024 conference a new update to SwiftData allows it to connect to other kind of data sources or databases, at ;east this is what I understood, since then didn't see any tutorial or help document on how to do that for example connecting SwiftData to Firebase if possible ? Kind Regards
Replies
0
Boosts
0
Views
267
Activity
Nov ’24
SwiftData preview sample code
Hi, re: the SwiftData session Create an app with SwifData (https://developer.apple.com/videos/play/wwdc2023/10154) I noted the mention of generating sample preview data. In CoreData, I had a similar need and this was achieved by creating a shared in-memory context; fairly straight forward. The example given for SwiftData was decorated with @MainActor and then added to the target project, then in the #Preview closure, the modelContainer is amended to point to the preview data. Anyways, my problem is that I'm receiving an error when trying to render the preview in question: main actor-isolated let 'previewContainer' can not be referenced from a non-isolated context I suppose my issue is not having used the MainActor wrapper before and being unclear on what's possibly going wrong here (or if it's not just a me problem). Can anyone help?
Replies
6
Boosts
0
Views
6.1k
Activity
Jun ’23
Optionally use iCloud with SwiftData
How do I make iCloud optional when using SwiftData? Not all users will have an iCloud account, or allow my app to use iCloud. I want it to gracefully, silently use a local store instead of iCloud if iCloud isn't available. It should also silently handle when the user switches iCloud on or off.
Replies
1
Boosts
0
Views
884
Activity
Sep ’23
Bug in .onmove for SwiftData models
I modified the default Items example from xcode to include two models, a view with a query and a detail view. On this detail view I cannot properly move all items, only the top two, please see the attached video. Especially strange is that some dragging does work and some does not. It changes with the number of sub-items on a todo. The models are SwiftData and it is have a one-to-many relationship. On the many relationship the problem exists. How should the code be adjusted to make sure all items are draggable? https://imgur.com/a/n1y7iXX Below is all code necessary for the minimal example. I target iOS 17.5 and this shows on both preview, simulator and my iPhone. Models @Model final class ToDo { var timestamp: Date var items: [Item] init(timestamp: Date) { self.timestamp = timestamp self.items = [] } } @Model final class Item { var timestamp: Date var done: Bool init(timestamp: Date, done: Bool) { self.timestamp = timestamp self.done = done } } ItemListView (Here is the problem!) s
Replies
2
Boosts
0
Views
1.2k
Activity
May ’24
SwiftData + CloudKit: BGSystemTaskScheduler Code=8
Hi everyone, On macOS 26.4 beta (with Xcode 26.4 beta), I’m seeing the following console messages in a brand new SwiftData + CloudKit template project (no custom logic added, fresh CloudKit container): updateTaskRequest called for a pre-running task com.apple.coredata.cloudkit.activity.export.F9EE783D-7521-4EC2-B42C-9FD1F29BA5C4 updateTaskRequest called for an already running/updated task com.apple.coredata.cloudkit.activity.export.F9EE783D-7521-4EC2-B42C-9FD1F29BA5C4 Error updating background task request: Error Domain=BGSystemTaskSchedulerErrorDomain Code=8 (null) These messages appear: When CloudKit is enabled Occasionally on app launch Often when bringing the app back to the foreground (Cmd-Tab away and back) Even with zero additional SwiftData logic They do not appear when CloudKit is disabled. This behavior is reproducible on a completely new project with a fresh CloudKit container. Questions: What exactly do these messages indicate? Is BGSystemTaskScheduler Code=8 expected in this con
Replies
2
Boosts
0
Views
201
Activity
Feb ’26