I’ve struggled to know what to write down about SwiftData since its debut a couple of weeks in the past, however Pietro Rea’s latest article impressed me. Take a second to learn it earlier than we proceed.
A extra Swift-friendly information persistence framework is a really welcome addition to our toolkit, however Pietro is right when he says:
Core Information’s predominant downside was not a technical downside. It was a advertising and marketing downside!
Establishing a Core Information undertaking isn’t excessively difficult, however it may be intimidating, particularly for newcomers to Apple platform improvement. A few years in the past, I delivered Goal-C and iOS improvement coaching programs, and Core Information all the time felt like a step too far for a five-day course the place college students began with no Goal-C information on day one. The code-first method of SwiftData feels immediately extra approachable, a lot in order that I might need thought of protecting it in that very same coaching session. That’s an enormous step ahead.
However Core Information might additionally really feel a bit of an excessive amount of for some duties, leaving you with choices to make. “Does this information deserve Core Information, or would an atomically loaded property checklist file match the duty higher?” I additionally don’t get that feeling anyplace close to as a lot with SwiftData.
However whereas it’s all the time enjoyable to get one thing new, it will be so wasteful to throw away the trouble that Apple invested into Core Information over the eight years it has been round, particularly when it ties so carefully to CloudKit and plenty of different applied sciences. New code means new bugs and the worst bugs lurk in information persistence code.
So, I used to be delighted to learn this line:
SwiftData makes use of the confirmed storage structure of Core Information, so you should use each in the identical app with the identical underlying storage.
It’s not totally clear to me how a lot of Core Information stays, and it’s nonetheless early days to name SwiftData a triumph because it’s nonetheless in beta, however Apple could have gotten it proper with SwiftData.
I can’t wait to confidently reply “How ought to I retailer information in my app?” with a easy “SwiftData”.