9 ms·
SwiftData
- tifa2up 3y agoNoob here, how does SwiftData compare to Redux (as a paradigm)?
- jahewson 3y agoLooks pretty different. Much closer to more modern state management approaches such as Recoil and Jotai.
- _trackno5 3y agoI don't get what you're saying here. Swift Data is just a framework to annotate data structures to be stored by Core Data. It looks a lot like an ORM.
- jahewson 3y agoIf we think of CoreData's role here as simply providing persistent storage then the annotation layer is the interesting bit - binding a persisted model to a view via a query is conceptually similar to Recoil's atoms' support for complex fetching, persistence, and offline support.
- bigtechennui 3y agoThinking of CoreData as simply providing the persistence layer is incorrect. It also provides the schema. CoreData’s object graph management and persistence are separate - you can use CoreData without persistence, but you can’t use it without a schema. The annotations are for defining the CoreData schema – i.e. the necessary piece – rather than relying on a schema definition file as one would prior to SwiftData. There are additional syntactic niceties for SwiftUI binding, but the annotations are very much an ORM.
- esprehn 3y agoWhat part makes you think of Recoil? CoreData (and now SwiftData over it) are more like ActiveRecord in my experience.
- jahewson 3y agoYes, that's CoreData but we're talking about this new intermediate SwiftData layer. If you think of the ORM part as just "storage" the bindings are quite Recoil-like. Take a look at `recoil-sync`, which handles querying and syncing with persistent storage.
- RandallBrown 3y agoIt's not really comparable. SwiftData is the Swift version of Apple's CoreData, which is pretty much a database ORM. It's a massive improvement on the old APIs that were written decades ago for Obj-C.
- manmal 3y agoIf you need Redux in SwiftUI, you should check out ComposableArchitecture.
- trinix912 3y agoIt’d be interesting to see a performance comparison of SwiftData vs. (objc?) CoreData vs. plain XML for large datasets. I recall plain XMLs being faster than CoreData a few years ago in certain scenarios.
- akmarinov 3y agoIsn't SwiftData mostly a wrapper around CoreData?
- koinedad 3y agoMost definitely
- akmarinov 3y agoThen there probably won't be a difference in performance
- favorited 3y agoThere certainly could be. SwiftData @Models aren't subclasses of NSManagedObject, and don't have to use the Objective-C runtime for dispatch, or the KVC-style property accessors that Core Data uses. The fact that it is built atop Core Data's persistent stores, cloud sync, etc. doesn't mean that it's a fascade in front of the Objective-C APIs.
- afinlayson 3y agoIt just makes it easier to use - meaning less glue code. Making CoreData Swift + SwiftUI native approach. Where currently you'd have to make a Core Data class wrapped by a @Observable Class.
- koinedad 3y ago“Combining Core Data’s proven persistence technology and Swift’s modern concurrency features, SwiftData enables you to add persistence to your app quickly”
- zyang 3y agoIs this a ground up rewrite or just varnish over CoreData.
- koinedad 3y agoI’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 3y agoThe 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 3y agoI 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 3y agoApple 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.
- yreg 3y agoI know, but even with my small app I don't feel comfortable dropping support for the 20% users who are behind. And if I'm supposed to maintain both the old and the new API in parallel then why bother. Now for new apps I can see going all in with the latest SDKs.
- valianteffort 3y agoI mean it's not too complicated to add OS specific exceptions in Swift. You can build your app for the lowest version you want to support and add newer OS features a la carte.
- 3y ago
- sureshv 3y agoLooks like a wrapper over core data - was wondering if they made it thread safe.
- sumuyuda 3y agoThis is a huge annoyance with CoreData, you can’t pass objects between threads.
- secretsatan 3y agoI remember tearing my hair out over that, i did eventually get it working reliably across the 2 threads i needed and i swore if i ever had to try again i’d try something else, it was just so easy to start with
- gfaure 3y agoI didn't know that Swift had a macro system...
- rescripting 3y agoThey were just introduced in Swift 5.9, released w/ the Xcode 15 beta: https://developer.apple.com/videos/play/wwdc2023/10166/ https://developer.apple.com/videos/play/wwdc2023/10166/
- elthor89 3y agoI was waiting for this to come out. Hope to have sometime this weekend to play with it.
- mrtksn 3y agoI 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?
- wilg 3y ago> Why wouldn’t Apple make these available downstream? Because Apple cannot figure out that their deployment model is hamstringing adoption of their technologies.
- plagiarist 3y agoThey 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/0376-function-back-deployment.md https://github.com/apple/swift-evolution/blob/main/proposals...
- _2z1p 3y agoOver 80% of iPhones are running the latest version. I’ll take that any day as a developer over the Android hellscape of versions that need to be tested for and supported. https://www.macrumors.com/2023/06/01/apple-shares-ios-16-adoption-statistics/ https://www.macrumors.com/2023/06/01/apple-shares-ios-16-ado...
- seanalltogether 3y agoOne 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 3y agoCMD+F @Model would largely address the issue of not having an overview of the schema.
- refulgentis 3y agoNot quite, having a list of lines it appears in won't be as helpful as the UML-ish graph.
- codetrotter 3y agoEither Apple will add some graph tools to Xcode, or third-parties will develop tools to make the graphs you need
- refulgentis 3y agoOkay awesome, great news (what is going on here, exactly? why do we need to solve this and tie it off with a bow, today? why is 'maybe someone else or maybe them will maybe make something similar someday' a resolution?)
- wahnfrieden 3y agoput them in one file then.
- leovander 3y ago
- amadeuspagel 3y agoSync really needs to be a feature of the web platform. A web app should be able to ask the user to sync its data accross devices. There's no reason you should have to worry about sync and authentication when you make an offline first web app.
- tantalor 3y agoEr, how would that even work? Apple can sync over iCloud. What are Firefox users going to sync over?
- astrange 3y agoThey do have something called Firefox Sync. It doesn't do that though.
- amadeuspagel 3y agoObviously the browser has to provide this backend. Browsers already sync passwords, history, bookmarks, extension data, they should offer sync as a feature for the web app as well.
- tantalor 3y agoThat's fine but then it's not really a feature of the web... it's a browser feature. You are totally locked into that browser. Compare to browser bookmarks. Not a "web feature".
- amadeuspagel 3y agoThere are a bunch of web features about integrating with the browsers password manager: https://web.dev/security-credential-management/ https://web.dev/security-credential-management/ These of course lock you into the browser (or the password manager) to the same extent. (Of course, just as a browser might support different password managers, so it might support different sync back ends.)
- jahewson 3y ago
- fareesh 3y agoVery nice changes. It's a shame to see cross-platform development tools falling so far behind.
- mark_l_watson 3y agoWhen 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 3y agoYeah 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
- BooneJS 3y agoThere’s a number of indie devs who rely on https://github.com/ccgus/fmdb 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 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 3y 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.
- jinjin2 3y agoLooks promising and it is about time that they modernized the interface to CoreData that was getting really long in the tooth by now. I still prefer Realm though. It has a much more flexible days model and I can use it both on iOS and Android with seamless sync between the two. When Apple adds cross-platform sync to SwiftData I’ll consider it. Until then it is dead in the water.
- ChrisMarshallNY 3y agoThis looks interesting to me. I have been a bit spooked on Core Data, after a friend of mine had a months-long ordeal with it; finally giving up on it, and setting up his own file-based DB. But I do have use cases for this kind of thing.
- koinedad 3y agoCore data is nice for the whole package of built in persistence and cloud sync…but can be annoying to setup
- jamil7 3y agoUnfortunately 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 3y agoIt 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.
- w10-1 3y agoThis 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.