|
I'm doing a test project to learn how to upgrade from CoreData to SwiftData. The problem that I'm having is that after changing to SwiftData, the data created from when the app was CoreData isn't showing up. Here's the steps I took.
Changing from CoreData to SwiftData
Now I run the app. No errors or warnings. App runs on the same device. No timestamps are there. Click the plus button and can create new ones. But it should show the 5 that were created with CoreData. What am I missing?
|
|
SwiftData Magic!Behind the scenes, SwiftData creates a number of tables to represent your actual model. Apple's Swift boffins have written this boiler plate code for you. I recommend you take a look at the tables created by CoreData, then compare them to the tables created by SwiftData. To see the table elements SwiftData produces, you can use an SQL editor, navigate to the actual datastores, and take a look inside. Warning! It's quite gnarly! Stewart Lynch has a nice series on SwiftData on YouTube. In his series, he uses an SQL editor to peek inside datastores to demonstrate what SwiftData is doing. This may help you visualize the five records you store in CoreData, then determine if your SwiftData files read from the same files. See -> SwiftData: CRUD Operations Keep Coding!This will be an interesting adventure. Please return here and share your findings. |
|
hi Dennis, the short answer to your question is: Core Data defaults its store to a file with extension @Obelix gives you a great reference to the Lynch series. at some point (i don't know if it's in the first video in the series or maybe later), Stewart will show how you can more carefully control how SwiftData gets set up. of particular interest, Stewart shows how to create the SwiftData modelContainer directly at app startup (not using it would seem possible that if you set the URL to the old Core Data what could go wrong? you'd have to hope that the older sqlite file matches your SwiftData model exactly. since you defined the model using Xcode's creation directly from the older Core Data model, one hopes all will be well. (emphasis on hopes) i'll also be curious to hear what you find out. hopes that helps, DMG |
|
Jerry helps with
Yes! This is the idea I was hoping @Dennis would follow. |
|
Thanks to @Obelix, @delewaremathguy and Stewart Lynch, the answer to this is sort of simple. I tested the code on both the CDTest01 and one of my apps and there don't appear to be any issues. I'll do a lot more testing before i put it out to the world.
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.