Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

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
Core-Data one-to-many relationship
Hello, I have the problem that I want to create a relationship between a list and its items. I have created relationships and also selected one-to-many for the list. But when I create multiple lists and add an item in the list, this item is added to each list and not only to the one. How can I set that the item is only added to the list that was selected? Lists code import SwiftUI import CoreData import Foundation struct ContentView: View { @Environment(.managedObjectContext) private var viewContext @FetchRequest(sortDescriptors: []) var items: FetchedResults @State private var name: String = var body: some View { NavigationView { VStack{ TextField(Text eingeben, text: $name) .padding() Button { addItem() } label: { Text(Save) }.padding() List { ForEach(items, id: .self) { item in NavigationLink(destination: ToDo()) { Text(item.name ?? Not found) } // Text(item.name ?? Not found) } .onDelete(perform: deleteItems) } } } } private func addItem() { withAnimation { let newItem = Item(context: v
2
0
1.5k
Jan ’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
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 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
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
Core-Data one-to-many relationship
Hello, I have the problem that I want to create a relationship between a list and its items. I have created relationships and also selected one-to-many for the list. But when I create multiple lists and add an item in the list, this item is added to each list and not only to the one. How can I set that the item is only added to the list that was selected? Lists code import SwiftUI import CoreData import Foundation struct ContentView: View { @Environment(.managedObjectContext) private var viewContext @FetchRequest(sortDescriptors: []) var items: FetchedResults @State private var name: String = var body: some View { NavigationView { VStack{ TextField(Text eingeben, text: $name) .padding() Button { addItem() } label: { Text(Save) }.padding() List { ForEach(items, id: .self) { item in NavigationLink(destination: ToDo()) { Text(item.name ?? Not found) } // Text(item.name ?? Not found) } .onDelete(perform: deleteItems) } } } } private func addItem() { withAnimation { let newItem = Item(context: v
Replies
2
Boosts
0
Views
1.5k
Activity
Jan ’23
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
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
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
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
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
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