Excellent, Paul! I purchased your book about SwiftData, super helpful! As it happens I am only seeing the video now a month later which is cool. Thank you for all you do!
Good day! Amazing tutorial, could you tell how we can sort Sights? It may be useful for someone, who creating chat and put messages inside chat model, like you put Sight into Destination 🙂
How about if Sights had several other fields, and I wanted to move to a subview to further edit a Sight? How would we access the model context in order to persist changes to those particular objects? A new subview for editing Sights does not appear to like me bringing in the context with @Environment (only the top-level app object only has access to the modelContainer?). Would we pass just the Sight to the subview, or the whole Destination?
The EditDestinationView preview always crashes when appending to the sights array - tried a bunch of different things but I'm quite lost, is there anything that can be done in order for it to work?
I can work around the preview issue by using a codable struct instead of the sight @Model but this is super strange... // This works struct Sight: Codable { var name: String } // This explodes @Model class Sight { var name: String init(name: String) { self.name = name } }
In previous betas, we had to perform migrations by writing code. As you point out, the migration in this episode is performed without any action or code being written by us; what was previously referred to as a 'simple' migration. Is this now a general feature of SwiftData or are there more complex migrations that will still require coding on our part?
If you erase the contents and settings on the simulator device, then rebuild, the new simulator database will have the new code. It's only when doing complex migrations that you'll need to follow a schema migration plan. See Paul's article: "How to create a complex migration using VersionedSchema".
How does one delete a site that has been added? I tried wrapping the sites ForEach with a List, adding an .onDelete modifier that called a deleteSite method similar to the one in DestinationListingView. I added a modelContext environment variable to EditDestinationView but was getting xCode errors showing a type mismatch.
I tried that too, and Xcode opened up the macro code on class Sight, and at the line return self.getValue(forKey: \.name) there was an exception: Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1a8a4fad8) Not helpful at all. But I reran the app, and the Sight I had edited was gone.
the init doesn't need to set the variables that have a default value, and the sights array has the default value [Sight]() which is an empty array of sights
Excellent, Paul! I purchased your book about SwiftData, super helpful! As it happens I am only seeing the video now a month later which is cool. Thank you for all you do!
Where did you get it?
Omg.. this is magic. Migration after a adding a single new property in Core Data was an absolute horror nightmare. God bless SwiftData
Thank You so much! Best tutorial for SwiftData with sorts&searches! 🎉
Good day! Amazing tutorial, could you tell how we can sort Sights? It may be useful for someone, who creating chat and put messages inside chat model, like you put Sight into Destination 🙂
Some question came to my mind. what if I want to go from sight to its parent destination record, how can that be done ?
How about if Sights had several other fields, and I wanted to move to a subview to further edit a Sight? How would we access the model context in order to persist changes to those particular objects? A new subview for editing Sights does not appear to like me bringing in the context with @Environment (only the top-level app object only has access to the modelContainer?). Would we pass just the Sight to the subview, or the whole Destination?
Thanks for your great video! So if you could continue add sights, which are in normal order by adding ? Because mine's not 😭
When I add
var sights = [Sight]() I receive an error Variable’self’._$backData’ used before initialization?
The EditDestinationView preview always crashes when appending to the sights array - tried a bunch of different things but I'm quite lost, is there anything that can be done in order for it to work?
I can work around the preview issue by using a codable struct instead of the sight @Model but this is super strange...
// This works
struct Sight: Codable {
var name: String
}
// This explodes
@Model
class Sight {
var name: String
init(name: String) {
self.name = name
}
}
In previous betas, we had to perform migrations by writing code. As you point out, the migration in this episode is performed without any action or code being written by us; what was previously referred to as a 'simple' migration. Is this now a general feature of SwiftData or are there more complex migrations that will still require coding on our part?
If you erase the contents and settings on the simulator device, then rebuild, the new simulator database will have the new code. It's only when doing complex migrations that you'll need to follow a schema migration plan. See Paul's article: "How to create a complex migration using VersionedSchema".
How does one delete a site that has been added? I tried wrapping the sites ForEach with a List, adding an .onDelete modifier that called a deleteSite method similar to the one in DestinationListingView. I added a modelContext environment variable to EditDestinationView but was getting xCode errors showing a type mismatch.
I tried that too, and Xcode opened up the macro code on class Sight, and at the line
return self.getValue(forKey: \.name)
there was an exception: Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1a8a4fad8)
Not helpful at all.
But I reran the app, and the Sight I had edited was gone.
what happened to the rule that the init need to set every variable, particularly after you add the sights array?
The sights array is initialized where it's declared as an empty array
the init doesn't need to set the variables that have a default value, and the sights array has the default value [Sight]() which is an empty array of sights