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 current 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 Knowledge’s principal drawback was not a technical drawback. It was a advertising drawback!
Establishing a Core Knowledge challenge 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 Knowledge at all times 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 strategy of SwiftData feels immediately extra approachable, a lot in order that I might need thought-about masking it in that very same coaching session. That’s an enormous step ahead.
However Core Knowledge might additionally really feel somewhat an excessive amount of for some duties, leaving you with selections to make. “Does this knowledge deserve Core Knowledge, or would an atomically loaded property listing file match the duty higher?” I additionally don’t get that feeling wherever close to as a lot with SwiftData.
However whereas it’s at all times enjoyable to get one thing new, it could be so wasteful to throw away the trouble that Apple invested into Core Knowledge 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 knowledge persistence code.
So, I used to be delighted to learn this line:
SwiftData makes use of the confirmed storage structure of Core Knowledge, so you should use each in the identical app with the identical underlying storage.
It’s not completely clear to me how a lot of Core Knowledge stays, and it’s nonetheless early days to name SwiftData a triumph because it’s nonetheless in beta, however Apple might 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”.