Build an app with SwiftData

RSS for tag

Discuss the WWDC23 Build an app with SwiftData

Posts under wwdc2023-10154 tag

62 Posts

Post

Replies

Boosts

Views

Activity

How can I share SwiftData @Model between widget and app?
I have an App Group shared between my app and its widgets. I have SwiftData's @Model, updated from the widget intent's perform() method and displayed on the app and the widget. @MainActor func perform() async throws -> some IntentResult { let context = try ModelContainer(for: MyModel.self).mainContext let myModel = try ModelContainer(for: MyModel.self).mainContext.fetch( FetchDescriptor<MyModel>(predicate: #Predicate { // The predicate is not the problem. }) ).first myModel?.functionThatModifiesMyModel() return .result() } Both the app and the widget SwiftUI views access to the model using Macros. @Environment(\.modelContext) var context @Query(sort: \.whatever) var myModel: [MyModel] But the data is never correct in the app code (the widget's data is updated correctly using the intent). Why doesn't the model make it to the app?
4
0
2.0k
Aug ’23
How to use the .onMove SwiftUI modifier to reorder SwiftData elements?
I am new to SwiftData and I'm trying to use the .onMove modifier to rearrange "ChecklistItems" List { ForEach(items) { item in ChecklistItemsListRowView(item: item, checklist: checklist) .onTapGesture { item.completed.toggle() save() } // onTapGesture } .onDelete(perform: { indexes in for index in indexes { modelContext.delete(checklist.items[index]) } // *for* }) // onDelete .onMove { IndexSet, int in // TODO: Rearrange Elements } // onMove } // LIST This is my ChecklistItem class: @Model final class ChecklistItem { @Attribute(.unique) var creationDate: Date var name: String var priority: Int var notes: String var completed: Bool var checklist: Checklist? init(creationDate: Date, name: String, priority: Int, notes: String, completed: Bool) { self.creationDate = creationDate self.name = name self.priority = priority self.notes = notes self.completed = completed } } extension ChecklistItem { @Transient static var preview = ChecklistItem(creationDate: Date(), name: "Item", priority: 2, notes: "This is a note.", completed: true) }
3
1
4.2k
Aug ’23
SwiftData nested custom model CRASH
@Model class AModel { @Attribute(.unique) var id:String var date:Date var b:[BModel] init() { self.id = UUID().uuidString self.date = Date() self.b = [] } } @Model class BModel { @Attribute(.unique) var id:String var date:Date init() { self.id = UUID().uuidString self.date = Date() } } struct MainView: View { @Environment(\.modelContext) private var db @State private var a:AModel = AModel() var body: some View { VStack { } .onAppear { a.b.append(BModel()) print(a.b) } } } // CRASH : @Model class AModel { @Attribute(.unique) var id:String var date:Date var b:[BModel] /** Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) { get { _$observationRegistrar.access(self, keyPath: \.b) return self.getValue(for: \.b) } set { _$observationRegistrar.withMutation(of: self, keyPath: \.b) { self.setValue(for: \.b, to: newValue) } } } */ init() { self.id = UUID().uuidString self.date = Date() self.b = [] } } @Model class BModel { @Attribute(.unique) var id:String var date:Date init() { self.id = UUID().uuidString self.date = Date() } }
3
4
2.2k
Aug ’23
CoreData: error: CoreData: error: Row (pk = 1) for entity 'MergeRequest' is missing mandatory text data for property 'id'
I'm converting my app to use SwiftData. I have a class called MergeRequest which everytime I insert it into the modelContext it fails with the following error: CoreData: error: CoreData: error: Row (pk = 1) for entity 'MergeRequest' is missing mandatory text data for property 'id' CoreData: error: CoreData: error: Row (pk = 2) for entity 'MergeRequest' is missing mandatory text data for property 'id' (... repeated for each inserted item) When I print the id before inserting the class does have a coredata generated id. PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(url: x-coredata:///MergeRequest/t5B3316FC-DBE0-4440-88E5-8EDFBA7E856A3), implementation: SwiftData.PersistentIdentifierImplementation) This is where I insert the model: https://github.com/StefKors/GitLab/blob/cb4c1ef6dec616d5ac146d712658496095c82243/Shared/UserInterface/UserInterface.swift#L137 And this is the full model class: https://github.com/StefKors/GitLab/blob/cb4c1ef6dec616d5ac146d712658496095c82243/Shared/UserInterface/SwiftData/MergeRequest.swift What I don't get is why does this error happen while it does have an id. Is there some debugging I can do to get more information?
1
0
1.3k
Aug ’23
Is it safe to mark SwiftData (@Model) classes as Sendable?
The Sendable documentation says we can mark reference types as Sendable if they "internally manage access to their state." Adding Sendable conformance to my SwiftData classes silences warnings such as the following: "Non-sendable type '[Item]' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary" @Model final class Item: Sendable { var sampleProperty = "" } My understanding is that the compiler would complain if adding explicit Sendable conformance to a swift data model was breaking concurrency rules, but I wanted to check with the community to see what everyone thinks. Best, Taylor
2
1
2.5k
Aug ’23
Problem compiling @Model
I tried coding along with the WWDC23 'Dive Deeper into SwiftData' video but can't get the sample code to compile. For example the Card class fails with lots of errors associated with @Model. The first of these is: Type 'Card' does not conform to protocol 'PersistentModel' import SwiftUI import SwiftData @Model final class Card { var front: String var back: String var creationDate: Date init(front: String, back: String, creationDate: Date = .now) { self.front = front self.back = back self.creationDate = creationDate } } On the other hand the following stand alone code (in it's own project) compiles without error. So I am confused and a little fed up with Apple publishing sample code that doesn't compile. import SwiftData @Model final class Card { var front: String var back: String var creationDate: Date init(front: String, back: String, creationDate: Date = .now) { self.front = front self.back = back self.creationDate = creationDate } } struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .padding() } } #Preview { ContentView() }
1
0
661
Aug ’23
How the new relationships in SwiftData work?
There is a new Relationship macro in Xcode Beta 6. The macro includes two new arguments: minimumModelCount and maximumModelCount. I wonder if anyone knows what these values are for and if there is another change under the hood. Relationship( _ options: PropertyOptions..., deleteRule: Schema.Relationship.DeleteRule = .nullify, minimumModelCount: Int? = 0, maximumModelCount: Int? = 0, originalName: String? = nil, inverse: AnyKeyPath? = nil, hashModifier: String? = nil )
1
1
867
Aug ’23
Relationship Fault not happening in SwiftData
I have two models a Person and a Possession the Person model has a one to many relationship to the Possession model. meaning each possession can only have one person but a person can have multiple possessions. I have set my model like the following Person: @Model class Person { @Attribute(.unique) let personID: String @Relationship(.cascade, inverse: \Possession.person) var possetions: [Possession]? init(id: String, possessions: [Possession]) { self.personID = id self.possetions = possessions } } Possession: @Model class Possession { @Attribute(.unique) let id: String let name: String? var person: Person? init(id: String, name: String, person: Person) { self.id = id self.name = name self.person = person } } If i set a breakpoint i see that all the posessions are loaded into the memory this is something i do not want to happen. In Core Data we get a relationship fault however, i am not seeing the same behavior in SwiftData. here's how my view is implemented struct ContentView: View { @Environment(\.modelContext) private var modelContext @EnvironmentObject private var navigationStore: NavigationStore @Query() private var people: [Person] var body: some View { List { ForEach(people) { person in NavigationLink(value: person) { VStack { Text(person.personID) } } .swipeActions { Button("Delete") { modelContext.delete(person) } } } } .toolbar(content: { Button("Add") { let newPErson = Person(id: UUID().uuidString, possessions: []) modelContext.insert(newPErson) do { try modelContext.save() } catch { assertionFailure("\(error)") } } }) .navigationDestination(for: Person.self) { person in Text("hello") } } } at the launch i do not want posessions to be loaded into the memory. I want them loaded when they are being used.
0
0
937
Jul ’23
SampleData on Previews @MainActor issue
Hi all, I am trying to render my SwiftUI views that uses SwiftData classes using sample data using the approach shown in the example code of wwdc2023-10196: @MainActor #Preview { TripsWidgetEntryView() .modelContainer(PreviewSampleData.container) } Unfortunately this seems no longer valid. Indeed I get this error: I then tried to remove the @MainActor as suggested, but the error in then moved to another level: What do you suggest to be the best approach to have back my preview working? I am using Xcode Beta 4 - 15A5195m
4
0
1.2k
Jul ’23
Error with Xcode 15 beta 5
I am getting the following error on this line of code @Query(sort: \.id, order: .reverse) private var artList: [ArtInventory] Cannot infer key path type from context; consider explicitly specifying a root type So, I select fix and then the line of code then look like this @Query(sort: \<#Root#>.id, order: .reverse) private var artList: [ArtInventory] with this error Invalid component of Swift key path Some seems to have changed with the @Query macro in beta 5, which now needs a root type, but not sure how to proceed. Any ideas how to fix?
1
1
1.6k
Jul ’23
Previews are not building for the SwiftDataCardSample project.
I set my active schema to SwiftDataCardSampleEnd, open ContentView.swift, and bring up the Canvas. When I click the little refresh button I get the follow error from Canvas: == DATE: Friday, July 14, 2023 at 9:02:26 AM Eastern Daylight Time 2023-07-14T13:02:26Z == PREVIEW UPDATE ERROR: SchemeBuildError: Failed to build the scheme ”SwiftDataFlashCardSampleEnd” linker command failed with exit code 1 (use -v to see invocation) Link SwiftDataFlashCardSample (arm64): ld: Undefined symbols: unsafeMutableAddressor of self #1 : SwiftDataFlashCardSample.Card in SwiftDataFlashCardSample.Card.creationDate.init : Foundation.Date, referenced from: SwiftDataFlashCardSample.Card.creationDate.init : Foundation.Date in Card.o unsafeMutableAddressor of self #1 : SwiftDataFlashCardSample.Card in SwiftDataFlashCardSample.Card.back.init : Swift.String, referenced from: SwiftDataFlashCardSample.Card.back.init : Swift.String in Card.o unsafeMutableAddressor of self #1 : SwiftDataFlashCardSample.Card in SwiftDataFlashCardSample.Card.front.init : Swift.String, referenced from: SwiftDataFlashCardSample.Card.front.init : Swift.String in Card.o clang: error: linker command failed with exit code 1 (use -v to see invocation) I've made a similar preview in another project where I define a model and I try to use that model in a SwiftUI Canvas preview. I get a very similar error. Basically Canvas is saying it can't find the symbols for the properties on the type. Is there something I'm missing here? Some hidden build setting I need to flip. Or is this just busted?
4
0
1.4k
Jul ’23
What is the difference between swiftdata and coredata?
What is the difference between swiftdata and coredata? I am coding by integrating coreda and icloud. As introduced at wwdc, I heard that it can be used more easily in xcode. However, for me who has to sell it tomorrow, the stability of swiftdata after the official release of ios17 in the future is low, and scalability and modification are difficult. If it's difficult, it's a lot of trouble. And the most important thing, is there any difference from coredata by using swiftdata in the experience of my valuable customers who use my program? I'm well aware that everyone is learning and discussing. Thank you for sharing your experience.
2
2
1.3k
Jul ’23
SwiftData - Multiple modelContexts in one modelContainer
In the WWDC presentations, it was mentioned that you could have multiple modelContexts within one modelContainer. Does anyone know of any examples of a project with multiple modelContexts? Specifically, I'm wondering how you distinguish between the two different modelContexts when doing things like @Query. I'd like to keep different sets of data in separate modelContexts and only Query the one that I want to pull from for a particular view. Thanks in advance!
2
2
2.7k
Jul ’23
How can I share SwiftData @Model between widget and app?
I have an App Group shared between my app and its widgets. I have SwiftData's @Model, updated from the widget intent's perform() method and displayed on the app and the widget. @MainActor func perform() async throws -> some IntentResult { let context = try ModelContainer(for: MyModel.self).mainContext let myModel = try ModelContainer(for: MyModel.self).mainContext.fetch( FetchDescriptor<MyModel>(predicate: #Predicate { // The predicate is not the problem. }) ).first myModel?.functionThatModifiesMyModel() return .result() } Both the app and the widget SwiftUI views access to the model using Macros. @Environment(\.modelContext) var context @Query(sort: \.whatever) var myModel: [MyModel] But the data is never correct in the app code (the widget's data is updated correctly using the intent). Why doesn't the model make it to the app?
Replies
4
Boosts
0
Views
2.0k
Activity
Aug ’23
How to use the .onMove SwiftUI modifier to reorder SwiftData elements?
I am new to SwiftData and I'm trying to use the .onMove modifier to rearrange "ChecklistItems" List { ForEach(items) { item in ChecklistItemsListRowView(item: item, checklist: checklist) .onTapGesture { item.completed.toggle() save() } // onTapGesture } .onDelete(perform: { indexes in for index in indexes { modelContext.delete(checklist.items[index]) } // *for* }) // onDelete .onMove { IndexSet, int in // TODO: Rearrange Elements } // onMove } // LIST This is my ChecklistItem class: @Model final class ChecklistItem { @Attribute(.unique) var creationDate: Date var name: String var priority: Int var notes: String var completed: Bool var checklist: Checklist? init(creationDate: Date, name: String, priority: Int, notes: String, completed: Bool) { self.creationDate = creationDate self.name = name self.priority = priority self.notes = notes self.completed = completed } } extension ChecklistItem { @Transient static var preview = ChecklistItem(creationDate: Date(), name: "Item", priority: 2, notes: "This is a note.", completed: true) }
Replies
3
Boosts
1
Views
4.2k
Activity
Aug ’23
SwiftData nested custom model CRASH
@Model class AModel { @Attribute(.unique) var id:String var date:Date var b:[BModel] init() { self.id = UUID().uuidString self.date = Date() self.b = [] } } @Model class BModel { @Attribute(.unique) var id:String var date:Date init() { self.id = UUID().uuidString self.date = Date() } } struct MainView: View { @Environment(\.modelContext) private var db @State private var a:AModel = AModel() var body: some View { VStack { } .onAppear { a.b.append(BModel()) print(a.b) } } } // CRASH : @Model class AModel { @Attribute(.unique) var id:String var date:Date var b:[BModel] /** Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) { get { _$observationRegistrar.access(self, keyPath: \.b) return self.getValue(for: \.b) } set { _$observationRegistrar.withMutation(of: self, keyPath: \.b) { self.setValue(for: \.b, to: newValue) } } } */ init() { self.id = UUID().uuidString self.date = Date() self.b = [] } } @Model class BModel { @Attribute(.unique) var id:String var date:Date init() { self.id = UUID().uuidString self.date = Date() } }
Replies
3
Boosts
4
Views
2.2k
Activity
Aug ’23
CoreData: error: CoreData: error: Row (pk = 1) for entity 'MergeRequest' is missing mandatory text data for property 'id'
I'm converting my app to use SwiftData. I have a class called MergeRequest which everytime I insert it into the modelContext it fails with the following error: CoreData: error: CoreData: error: Row (pk = 1) for entity 'MergeRequest' is missing mandatory text data for property 'id' CoreData: error: CoreData: error: Row (pk = 2) for entity 'MergeRequest' is missing mandatory text data for property 'id' (... repeated for each inserted item) When I print the id before inserting the class does have a coredata generated id. PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(url: x-coredata:///MergeRequest/t5B3316FC-DBE0-4440-88E5-8EDFBA7E856A3), implementation: SwiftData.PersistentIdentifierImplementation) This is where I insert the model: https://github.com/StefKors/GitLab/blob/cb4c1ef6dec616d5ac146d712658496095c82243/Shared/UserInterface/UserInterface.swift#L137 And this is the full model class: https://github.com/StefKors/GitLab/blob/cb4c1ef6dec616d5ac146d712658496095c82243/Shared/UserInterface/SwiftData/MergeRequest.swift What I don't get is why does this error happen while it does have an id. Is there some debugging I can do to get more information?
Replies
1
Boosts
0
Views
1.3k
Activity
Aug ’23
Is it safe to mark SwiftData (@Model) classes as Sendable?
The Sendable documentation says we can mark reference types as Sendable if they "internally manage access to their state." Adding Sendable conformance to my SwiftData classes silences warnings such as the following: "Non-sendable type '[Item]' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary" @Model final class Item: Sendable { var sampleProperty = "" } My understanding is that the compiler would complain if adding explicit Sendable conformance to a swift data model was breaking concurrency rules, but I wanted to check with the community to see what everyone thinks. Best, Taylor
Replies
2
Boosts
1
Views
2.5k
Activity
Aug ’23
Does SwiftData support UIImage
Does SwiftData support UIImage as in CoreData specified here: https://www.swiftdevjournal.com/saving-images-in-core-data/ If it does, how to specify that in the @Model schema, especially using external storage to save the image in a separate file. Thanks.
Replies
3
Boosts
1
Views
2.8k
Activity
Aug ’23
SwiftDataFlashCardSample doesn't compile
I just installed Xcode beta 6 and tried compiling the SwiftData sample app. It fails with a couple of dozen compile errors. Clearly this must have worked for WWDC23 so what's gone wrong? The following says type 'Card' does not conform to protocol 'PersistentModel' @Model final class Card: PersistentModel { This seems pretty basic. Any suggestions
Replies
2
Boosts
0
Views
982
Activity
Aug ’23
Problem compiling @Model
I tried coding along with the WWDC23 'Dive Deeper into SwiftData' video but can't get the sample code to compile. For example the Card class fails with lots of errors associated with @Model. The first of these is: Type 'Card' does not conform to protocol 'PersistentModel' import SwiftUI import SwiftData @Model final class Card { var front: String var back: String var creationDate: Date init(front: String, back: String, creationDate: Date = .now) { self.front = front self.back = back self.creationDate = creationDate } } On the other hand the following stand alone code (in it's own project) compiles without error. So I am confused and a little fed up with Apple publishing sample code that doesn't compile. import SwiftData @Model final class Card { var front: String var back: String var creationDate: Date init(front: String, back: String, creationDate: Date = .now) { self.front = front self.back = back self.creationDate = creationDate } } struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .padding() } } #Preview { ContentView() }
Replies
1
Boosts
0
Views
661
Activity
Aug ’23
How the new relationships in SwiftData work?
There is a new Relationship macro in Xcode Beta 6. The macro includes two new arguments: minimumModelCount and maximumModelCount. I wonder if anyone knows what these values are for and if there is another change under the hood. Relationship( _ options: PropertyOptions..., deleteRule: Schema.Relationship.DeleteRule = .nullify, minimumModelCount: Int? = 0, maximumModelCount: Int? = 0, originalName: String? = nil, inverse: AnyKeyPath? = nil, hashModifier: String? = nil )
Replies
1
Boosts
1
Views
867
Activity
Aug ’23
SwiftUI SwiftData Previews not working as expected
re: the SwiftData session "Create an app with SwifData" (https://developer.apple.com/videos/play/wwdc2023/10154) I corrected the @MainActor issue, but it seems to only work with the main ContentView and not other views. I get the following error for TripListItem for example : failed to find a currently active container for Trip
Replies
4
Boosts
3
Views
4.6k
Activity
Jul ’23
SwiftData - Thread 1: Fatal error: Illegal attempt to use a nil as an Attribute
Hi, I get this error Thread 1: Fatal error: Illegal attempt to use a nil as an Attribute - type + CustomType when trying to use SwiftData on one of my main views, I wasn't seeing this error when I was working with other data types but some reason this started happening all of a sudden. Any clues as to what it might be?
Replies
5
Boosts
1
Views
2.2k
Activity
Jul ’23
Relationship Fault not happening in SwiftData
I have two models a Person and a Possession the Person model has a one to many relationship to the Possession model. meaning each possession can only have one person but a person can have multiple possessions. I have set my model like the following Person: @Model class Person { @Attribute(.unique) let personID: String @Relationship(.cascade, inverse: \Possession.person) var possetions: [Possession]? init(id: String, possessions: [Possession]) { self.personID = id self.possetions = possessions } } Possession: @Model class Possession { @Attribute(.unique) let id: String let name: String? var person: Person? init(id: String, name: String, person: Person) { self.id = id self.name = name self.person = person } } If i set a breakpoint i see that all the posessions are loaded into the memory this is something i do not want to happen. In Core Data we get a relationship fault however, i am not seeing the same behavior in SwiftData. here's how my view is implemented struct ContentView: View { @Environment(\.modelContext) private var modelContext @EnvironmentObject private var navigationStore: NavigationStore @Query() private var people: [Person] var body: some View { List { ForEach(people) { person in NavigationLink(value: person) { VStack { Text(person.personID) } } .swipeActions { Button("Delete") { modelContext.delete(person) } } } } .toolbar(content: { Button("Add") { let newPErson = Person(id: UUID().uuidString, possessions: []) modelContext.insert(newPErson) do { try modelContext.save() } catch { assertionFailure("\(error)") } } }) .navigationDestination(for: Person.self) { person in Text("hello") } } } at the launch i do not want posessions to be loaded into the memory. I want them loaded when they are being used.
Replies
0
Boosts
0
Views
937
Activity
Jul ’23
SampleData on Previews @MainActor issue
Hi all, I am trying to render my SwiftUI views that uses SwiftData classes using sample data using the approach shown in the example code of wwdc2023-10196: @MainActor #Preview { TripsWidgetEntryView() .modelContainer(PreviewSampleData.container) } Unfortunately this seems no longer valid. Indeed I get this error: I then tried to remove the @MainActor as suggested, but the error in then moved to another level: What do you suggest to be the best approach to have back my preview working? I am using Xcode Beta 4 - 15A5195m
Replies
4
Boosts
0
Views
1.2k
Activity
Jul ’23
Error with Xcode 15 beta 5
I am getting the following error on this line of code @Query(sort: \.id, order: .reverse) private var artList: [ArtInventory] Cannot infer key path type from context; consider explicitly specifying a root type So, I select fix and then the line of code then look like this @Query(sort: \<#Root#>.id, order: .reverse) private var artList: [ArtInventory] with this error Invalid component of Swift key path Some seems to have changed with the @Query macro in beta 5, which now needs a root type, but not sure how to proceed. Any ideas how to fix?
Replies
1
Boosts
1
Views
1.6k
Activity
Jul ’23
SwiftData equivalent of the CoreData lifecycle methods
Anyone know the SwiftData equivalet of the CoreData lifecycle methods. and how do we override them or do something similar? eg: awakeFromInsert() willSave() didSave() willTurnIntoFault() prepareForDeletion()
Replies
0
Boosts
0
Views
914
Activity
Jul ’23
Performance optimizations?
I've noticed when using @Model instead of @Observable that it bumps the CPU-usage of the app with 10%, since I'm reading values on every frame of render. This seems to cause a deep lookup. Is there a way to read the objects/attributes in memory somehow?
Replies
0
Boosts
0
Views
772
Activity
Jul ’23
Previews are not building for the SwiftDataCardSample project.
I set my active schema to SwiftDataCardSampleEnd, open ContentView.swift, and bring up the Canvas. When I click the little refresh button I get the follow error from Canvas: == DATE: Friday, July 14, 2023 at 9:02:26 AM Eastern Daylight Time 2023-07-14T13:02:26Z == PREVIEW UPDATE ERROR: SchemeBuildError: Failed to build the scheme ”SwiftDataFlashCardSampleEnd” linker command failed with exit code 1 (use -v to see invocation) Link SwiftDataFlashCardSample (arm64): ld: Undefined symbols: unsafeMutableAddressor of self #1 : SwiftDataFlashCardSample.Card in SwiftDataFlashCardSample.Card.creationDate.init : Foundation.Date, referenced from: SwiftDataFlashCardSample.Card.creationDate.init : Foundation.Date in Card.o unsafeMutableAddressor of self #1 : SwiftDataFlashCardSample.Card in SwiftDataFlashCardSample.Card.back.init : Swift.String, referenced from: SwiftDataFlashCardSample.Card.back.init : Swift.String in Card.o unsafeMutableAddressor of self #1 : SwiftDataFlashCardSample.Card in SwiftDataFlashCardSample.Card.front.init : Swift.String, referenced from: SwiftDataFlashCardSample.Card.front.init : Swift.String in Card.o clang: error: linker command failed with exit code 1 (use -v to see invocation) I've made a similar preview in another project where I define a model and I try to use that model in a SwiftUI Canvas preview. I get a very similar error. Basically Canvas is saying it can't find the symbols for the properties on the type. Is there something I'm missing here? Some hidden build setting I need to flip. Or is this just busted?
Replies
4
Boosts
0
Views
1.4k
Activity
Jul ’23
What is the difference between swiftdata and coredata?
What is the difference between swiftdata and coredata? I am coding by integrating coreda and icloud. As introduced at wwdc, I heard that it can be used more easily in xcode. However, for me who has to sell it tomorrow, the stability of swiftdata after the official release of ios17 in the future is low, and scalability and modification are difficult. If it's difficult, it's a lot of trouble. And the most important thing, is there any difference from coredata by using swiftdata in the experience of my valuable customers who use my program? I'm well aware that everyone is learning and discussing. Thank you for sharing your experience.
Replies
2
Boosts
2
Views
1.3k
Activity
Jul ’23
SwiftData - Multiple modelContexts in one modelContainer
In the WWDC presentations, it was mentioned that you could have multiple modelContexts within one modelContainer. Does anyone know of any examples of a project with multiple modelContexts? Specifically, I'm wondering how you distinguish between the two different modelContexts when doing things like @Query. I'd like to keep different sets of data in separate modelContexts and only Query the one that I want to pull from for a particular view. Thanks in advance!
Replies
2
Boosts
2
Views
2.7k
Activity
Jul ’23
Problem with SwiftData
When trying to delete the element from my list, I always got error in my model. get { _$observationRegistrar.access(self, keyPath: \.id) return self.getValue(for: \.id) <-- ERROR: Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1a949aefc) } Because I am new in development, I don't know how to solve it.
Replies
2
Boosts
0
Views
3k
Activity
Jul ’23