Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

Reply to Swift complaining non-conformance to Encodable on protocol while Encodable is conformed
Unfortunately, in Swift, even if you declare a protocol inheriting some other protocol, the protocol you declared does not conform to the other protocol. In your case, your protocol TelegramId does inherit Encodable, but does NOT conform to Encodable. You need to specify a type conforming to Encodable, but your TelegramId does not. You may need to implement encode(to:) of Message by yourself. Or else you need to use some other type conforming to Encodable.
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’20
SwiftData and #DEBUG with the canvas...
Hi all, Very new to this. Just getting into swift data, and am frustrated with the canvas not working with modelContainers in SwiftData. My understanding is that they work if inMemory = true, but not in the default case where data is persistent after an app is quit. Can anyone tell me if it is possible to conditionally create the modelContainer type based on a flag... If Bool:Canvas then inMemory = True, Else False... Then using this flag for all data models so my list views populate on the canvas, without having to run the simulator each time... I would assume you could also pre-populate the inMemory option if it is empty also... Or is there a simple and obvious solution that I am oblivious to. If it is possible, is it worth the time, hassle, and any possible issues?
0
0
558
Dec ’24
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
Modifying SwiftData Object
Hi, The dataModule in code below is a swiftData object being passed to the view and its property as key path but when trying to modify it I'm getting the error .Cannot assign through subscript: 'self' is immutable how to solve this issue ? Kind Regards struct ListSel: View { @Bindable var dataModule: T @Binding var txtValue: String var keyPath: WritableKeyPath var turncate: CGFloat? = 94.0 var image = var body: some View { HStack { Text(txtValue) .foregroundColor(sysSecondary) .font(.subheadline) .onChange(of: txtValue) { value in dataModule[keyPath: keyPath] = value } Image(systemName: image) .foregroundColor(sysSecondary) .font(.subheadline) .imageScale(.small) .symbolRenderingMode(.hierarchical) .scaleEffect(0.8) } .frame(width: turncate, height: 20, alignment: .leading) .truncationMode(.tail) } }
2
0
501
Nov ’24
Reply to Swift's object syntax not the clearest or most efficient
I think the current syntax using final and override are fine. The reason is as follows. If you've made the decision to define a new class, most likely it is because, you are designing for inheritence or you are inheriting another class you need which may or may not be from Objective-C which has no concept of final classes. So, most likely you are using classes because you have made a decision that you need or want to embrace inheritance. With that decision comes the responsibility to manage inheritance which means deciding what is final and what is accessible.By default, classes, methods and properties have internal access. With whole module optimization, you get much of the benefit that you would get by marking members final when using internal access which is the default. Where things matter most from a safety and performance perspective is when you choose to make a class or member public. In doing so, you must take responsibility to decide whether to mark it final or not
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
SwiftData
I started playing around with the navigationDestination modifier. But currently it always re-routes me back to the list with the entries. Does someone have an idea why this happens? MainView NavigationStack { Form { Section { ProgressRing(percentage: $percentage) Text(1 of 3 compleatet) .font(.title2) .fontWeight(.medium) .foregroundStyle(Color.accentColor) } .listRowBackground(Color.clear) .listRowSeparator(.hidden) .frame(maxWidth: .infinity ,alignment: .center) .padding() Section(Daily tasks) { NavigationLink { EmptyView() } label: { Label(Log mood, systemImage: seal) } NavigationLink { QuoteView() } label: { Label(Quote Gallery, systemImage: seal) } NavigationLink { GratitudeListView() } label: { Label(Writing down gratitude, systemImage: seal) } } } .navigationTitle(Hello, (users.first?.name ?? User)) } List { ForEach(gratitudes, id: .self) { gratitude in NavigationLink(value: gratitude) { VStack(alignment: .leading) { Text(gratitude.gratitude1) Text(gratitude.createdAt, style: .date) } } } .navigationDe
0
0
622
Jan ’24
CloudKit integration requires does not support ordered relationships.
I'm trying to use Apple's CoreDataCloudkitDemo app. I've only changed the app settings per the README document. On running the demo, I'm getting the error: CloudKit integration requires does not support ordered relationships.The console log shows:Fatal error: ###persistentContainer: Failed to load persistent stores:Error Domain=NSCocoaErrorDomain Code=134060 A Core Data error occurred. UserInfo={NSLocalizedFailureReason=CloudKit integration requires does not support ordered relationships. The following relationships are marked ordered: Post: attachmentsDoes anyone have a workaround, or preferably, a fix? Or did I do something wrong?Thanks
6
0
5k
Jul ’19
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
Reply to iOS 18.1 and SeiftData
The solution to this was that prior to iOS 18 if you had a one to many relationship in your SwiftData models that adding to the array in the one data model entity would automatically update the many data item so that its optional attribute that pointed back to the data item containing the array of many items when you added items to the array. In iOS 18 now this is no longer true and if you don't set that optional attribute to explicitly point to the data model that will contain the array of many items then you will see the aforementioned error when you try to append the new item to that array. Hopefully this makes sense and will help someone down the road.
Aug ’24
Safari to app relationship
if you are on the tik tok website on safari, you are able to view a video that originally brought you to the website the from the search log, but if you want to click on another video listed on the website, it claims you need to use the app to go farther, and upon proceeding it just brings you to the App Store regardless if you have the app already or not , and you are unable to view the video displayed on the website without searching for it separately on the app.
2
0
437
Dec ’24
Reply to Swift complaining non-conformance to Encodable on protocol while Encodable is conformed
Unfortunately, in Swift, even if you declare a protocol inheriting some other protocol, the protocol you declared does not conform to the other protocol. In your case, your protocol TelegramId does inherit Encodable, but does NOT conform to Encodable. You need to specify a type conforming to Encodable, but your TelegramId does not. You may need to implement encode(to:) of Message by yourself. Or else you need to use some other type conforming to Encodable.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’20
SwiftData and #DEBUG with the canvas...
Hi all, Very new to this. Just getting into swift data, and am frustrated with the canvas not working with modelContainers in SwiftData. My understanding is that they work if inMemory = true, but not in the default case where data is persistent after an app is quit. Can anyone tell me if it is possible to conditionally create the modelContainer type based on a flag... If Bool:Canvas then inMemory = True, Else False... Then using this flag for all data models so my list views populate on the canvas, without having to run the simulator each time... I would assume you could also pre-populate the inMemory option if it is empty also... Or is there a simple and obvious solution that I am oblivious to. If it is possible, is it worth the time, hassle, and any possible issues?
Replies
0
Boosts
0
Views
558
Activity
Dec ’24
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
Modifying SwiftData Object
Hi, The dataModule in code below is a swiftData object being passed to the view and its property as key path but when trying to modify it I'm getting the error .Cannot assign through subscript: 'self' is immutable how to solve this issue ? Kind Regards struct ListSel: View { @Bindable var dataModule: T @Binding var txtValue: String var keyPath: WritableKeyPath var turncate: CGFloat? = 94.0 var image = var body: some View { HStack { Text(txtValue) .foregroundColor(sysSecondary) .font(.subheadline) .onChange(of: txtValue) { value in dataModule[keyPath: keyPath] = value } Image(systemName: image) .foregroundColor(sysSecondary) .font(.subheadline) .imageScale(.small) .symbolRenderingMode(.hierarchical) .scaleEffect(0.8) } .frame(width: turncate, height: 20, alignment: .leading) .truncationMode(.tail) } }
Replies
2
Boosts
0
Views
501
Activity
Nov ’24
Reply to Swift's object syntax not the clearest or most efficient
I think the current syntax using final and override are fine. The reason is as follows. If you've made the decision to define a new class, most likely it is because, you are designing for inheritence or you are inheriting another class you need which may or may not be from Objective-C which has no concept of final classes. So, most likely you are using classes because you have made a decision that you need or want to embrace inheritance. With that decision comes the responsibility to manage inheritance which means deciding what is final and what is accessible.By default, classes, methods and properties have internal access. With whole module optimization, you get much of the benefit that you would get by marking members final when using internal access which is the default. Where things matter most from a safety and performance perspective is when you choose to make a class or member public. In doing so, you must take responsibility to decide whether to mark it final or not
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
SwiftData
I started playing around with the navigationDestination modifier. But currently it always re-routes me back to the list with the entries. Does someone have an idea why this happens? MainView NavigationStack { Form { Section { ProgressRing(percentage: $percentage) Text(1 of 3 compleatet) .font(.title2) .fontWeight(.medium) .foregroundStyle(Color.accentColor) } .listRowBackground(Color.clear) .listRowSeparator(.hidden) .frame(maxWidth: .infinity ,alignment: .center) .padding() Section(Daily tasks) { NavigationLink { EmptyView() } label: { Label(Log mood, systemImage: seal) } NavigationLink { QuoteView() } label: { Label(Quote Gallery, systemImage: seal) } NavigationLink { GratitudeListView() } label: { Label(Writing down gratitude, systemImage: seal) } } } .navigationTitle(Hello, (users.first?.name ?? User)) } List { ForEach(gratitudes, id: .self) { gratitude in NavigationLink(value: gratitude) { VStack(alignment: .leading) { Text(gratitude.gratitude1) Text(gratitude.createdAt, style: .date) } } } .navigationDe
Replies
0
Boosts
0
Views
622
Activity
Jan ’24
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
CloudKit integration requires does not support ordered relationships.
I'm trying to use Apple's CoreDataCloudkitDemo app. I've only changed the app settings per the README document. On running the demo, I'm getting the error: CloudKit integration requires does not support ordered relationships.The console log shows:Fatal error: ###persistentContainer: Failed to load persistent stores:Error Domain=NSCocoaErrorDomain Code=134060 A Core Data error occurred. UserInfo={NSLocalizedFailureReason=CloudKit integration requires does not support ordered relationships. The following relationships are marked ordered: Post: attachmentsDoes anyone have a workaround, or preferably, a fix? Or did I do something wrong?Thanks
Replies
6
Boosts
0
Views
5k
Activity
Jul ’19
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
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
Reply to iOS 18.1 and SeiftData
The solution to this was that prior to iOS 18 if you had a one to many relationship in your SwiftData models that adding to the array in the one data model entity would automatically update the many data item so that its optional attribute that pointed back to the data item containing the array of many items when you added items to the array. In iOS 18 now this is no longer true and if you don't set that optional attribute to explicitly point to the data model that will contain the array of many items then you will see the aforementioned error when you try to append the new item to that array. Hopefully this makes sense and will help someone down the road.
Replies
Boosts
Views
Activity
Aug ’24
Safari to app relationship
if you are on the tik tok website on safari, you are able to view a video that originally brought you to the website the from the search log, but if you want to click on another video listed on the website, it claims you need to use the app to go farther, and upon proceeding it just brings you to the App Store regardless if you have the app already or not , and you are unable to view the video displayed on the website without searching for it separately on the app.
Replies
2
Boosts
0
Views
437
Activity
Dec ’24