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 knowledge persistence framework is a really welcome addition to our toolkit, however Pietro is appropriate when he says:
Core Information’s major downside was not a technical downside. It was a advertising and marketing downside!
Establishing a Core Information mission isn’t excessively difficult, however it may be intimidating, particularly for newcomers to Apple platform growth. A few years in the past, I delivered Goal-C and iOS growth 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 data on day one. The code-first method of SwiftData feels immediately extra approachable, a lot in order that I might need thought-about overlaying 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 selections to make. “Does this knowledge 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 could be so wasteful to throw away the hassle that Apple invested into Core Information over the eight years it has been round, particularly when it ties so carefully to CloudKit and lots of different applied sciences. New code means new bugs and the worst bugs lurk in knowledge 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 need to use each in the identical app with the identical underlying storage.
It’s not fully 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 knowledge in my app?” with a easy “SwiftData”.