Readit News logoReadit News
seanalltogether · 2 years ago
One of the things I like about CoreData is that all the relationships and entities are defined in one file, and its easier to browse the history of that schema to see how the models evolved. One of the things I dislike though is that it doesn't interop well with swift types and almost everything has to be marked as optional. It looks like this SwiftData solves the second problem, but since definitions are spread across all the classes individually, it's harder to get a glance at the whole schema at once.
jondwillis · 2 years ago
CMD+F @Model would largely address the issue of not having an overview of the schema.
refulgentis · 2 years ago
Not quite, having a list of lines it appears in won't be as helpful as the UML-ish graph.
wahnfrieden · 2 years ago
put them in one file then.
leovander · 2 years ago
Ditto to this suggestion. Especially when you auto generate classes it ends up creating the main class for each entity and a separate extension file for each. By default we merge the two and avoid the separate extension altogether.
jmull · 2 years ago
You still have the option to keep things organized, though you will need to supply a bit more of your own discipline.
TheJoeMan · 2 years ago
I hope all the swift tutorials don't switch to just SwiftData, seeing as how we must support iOS(-2).
wahnfrieden · 2 years ago
read tutorials authored up to wwdc(-2) then. tutorials cover the latest because that's where attention is.
throw74775 · 2 years ago
Why must you support iOS(-2)?
BooneJS · 2 years ago
There’s a number of indie devs who rely on https://github.com/ccgus/fmdb for fast persistence. The rebirth of NetNewsWire came with FMDB at its core (https://inessential.com/2020/05/18/why_netnewswire_is_fast). What’s not clear is if a project starts with, say, SwiftData, and finds it to be a bottleneck, how easy is it to remove unless one goes to great lengths to make a clean API between the 2?
wahnfrieden · 2 years ago
(For SQLite GRDB is more popular/refined)

I was all bought into RealmSwift, with iCloud syncing. Because I added a layer already that syncs Realm with iCloud, I expect transitioning to SwiftData (or from it to anything else) will work nearly out of box, without having to rip out the Realm code yet either. It'll receive the same iCloud data as Realm does.

mark_l_watson · 2 years ago
When out of beta and generally available, this will be useful! Ideally the iCloud sync will work across the same app built for macOS, iOS, and iPadOS.

I used SQLite a few years ago for a Swift/SwiftUI macOS app, and this looks like what I would have used if it was available. All in all, Apple is going in a good direction with Swift, SwiftUI, SwiftData, etc.

koinedad · 2 years ago
Yeah I’m feeling you on this. I built an iOS/MacOS app with iCloud sync in SwiftUI a few years ago and it was a chore
jamil7 · 2 years ago
Unfortunately it looks to be mostly papering over Core Data, after a few huge Core Data projects I don't really care to work with it anymore, especially in SwiftUI.

The more interesting addition to me looks to be CKSyncEngine, which would allow for easily adding a CloudKit sync engine to something like GRDB.

Defining models in structs and extending and conforming them to various protocols, using them in SwiftUI and passing them across threads feels much more natural to me.

ProtocolF1 · 2 years ago
It does seem like papering over Core Data, which is a papering over SQLite.

Can I ask what experience you had with CoreData and SwiftUI? And what do you prefer now instead? Thank you.

mrtksn · 2 years ago
I built myself something similar on top of SQLite and Combine.

Now I’m confused, should I abandon it and go with the first hand solution? I would actually prefer that but this requires the new versions of the Apple platforms. Why wouldn’t Apple make these available downstream?

lockhouse · 2 years ago
Apple actively encourages everyone to adopt the latest version. If your device is from 2018 or newer it will support the latest OS, so back porting frameworks is less important than on platforms like Android where devices are only updated for a much shorter duration and often several months after that version is released by Google.
alwillis · 2 years ago
> Why wouldn’t Apple make these available downstream?

Because it probably relies on new stuff that's only in the new version of the operating system. Otherwise, you'd have to back port a chunk of your new stuff to the older operating system, creating a lot more work for little gain.

And why do all of that when over 80% of the installed base will be running iOS 17 within 8 months, so what are you really gaining?

wilg · 2 years ago
> Why wouldn’t Apple make these available downstream?

Because Apple cannot figure out that their deployment model is hamstringing adoption of their technologies.

qwytw · 2 years ago
Why? This way their new stuff get a year or two of free testing and time to mature before widespread adoption.
plagiarist · 2 years ago
They actually can figure that out, though [0]. I hope this can solve some of it because their deployment model is the dumbest fucking thing. I'm glad they figured out how to backport async/await, it's just impossible to use in a serious library otherwise.

[0] https://github.com/apple/swift-evolution/blob/main/proposals...

manmal · 2 years ago
Apple need to ensure as many apps as possible raise their deployment target as soon as possible so that users with old devices are encouraged to upgrade to newer devices.
simonh · 2 years ago
The latest stuff is still compatible with 5 year old iPhones.

80% of iPhones run the latest OS precisely because they are dead serious about long term support for devices.

koinedad · 2 years ago
I’m actually really looking forward to this. I tried building a few apps in 100% SwiftUI coming from React/Node.js and it was a pretty major pain. I also don’t know UIKit so I couldn't easily fallback.
koinedad · 2 years ago
The typing of NSPredicate seems like a big upgrade as well. I went through all the old outdated docs for core data but still things aren’t very clear in my mind. Hoping the typing helps
yreg · 2 years ago
I had the same experience as you. Using CoreData with SwiftUI feels strange. Unfortunately if we start using this now we can only target iOS 17+.
valianteffort · 2 years ago
Apple has like >80% of devices released in last 5 years on iOS 16. Nowhere near the fragmentation of Android. Given only a minority of users are not on the latest major OS, worrying about supporting older firmware, at least in this case, is not worth the time or money.
mritchie712 · 2 years ago
Try it with ChatGPT. I've never built an iOS app and it took me 5 minutes to get a SwiftUI app running with gpt-4.
koinedad · 2 years ago
A basic app or one you created a bunch of custom logic, cloud sync integration, etc? I can build a simple app in a minute or two.
w10-1 · 2 years ago
This is made possible by Swift macros, which also will make migration easier.

I can imagine starting out with SwiftData @Model's, but then redefining the @Model macro to work with another backend -- even deploying the same models to different backends on different platforms (e.g., CoreData on iOS and MySQL on Linux).

"API-compatible" now includes attributes. This could be a great opportunity for alternatives to the CoreData stack.

zyang · 2 years ago
Is this a ground up rewrite or just varnish over CoreData.
mjmsmith · 2 years ago
Models still have to be classes, so it seems more like varnish.
vor_ · 2 years ago
Wouldn't they need to be classes in order to be observable objects for SwiftUI?
emehex · 2 years ago
This is really unfortunate... I wonder if they'll adapt the varnish to work with structs in a future release

Deleted Comment

geodel · 2 years ago
Seems like varnish.