Because I’ve been collecting code, tips and tricks on making a Mac app using SwiftUI, I wanted to not forget any of it, so I decided to make a little Snippett saver app in SwiftUI. Yesterday I started looking at databases in SwiftUI and I ended up swearing at the screen at how simple (to me) it seems.
Here’s a very quick tutorial from 0-30, for a single table database.
I’m still trying to understand how I’d make multiple table databases with relationships, I’ve watched a couple of videos, but still don’t fully get it yet…
Found a really complicated tutorial on many-to-many relationships in SwiftData… Oh boy…
This video is really cool as it shows how to make a document based database application.
I assume you are attempting to use CoreData or one of those other strange mechanisms Apple supplied?
Why not just use SQLite?
FYI… found another shortcoming for SwiftUI… it doesn’t support tvOS at all
I’m looking at the new shiny “SwiftData”.
I don’t know how it compares to Core Data as I never used it, but SwiftData appears to be designed for SwiftUI, and it appears to be mind numbingly simply to integrate. I’m hoping to give it a try later today.
Add @Model macro to your class and it defines the table for you…
I’ve seen it mentioned but never really paid attention as I have zero interest in Apple TV. I just did a quick Google and Apple appear to promote using SwiftUI for tvOS.
SwiftData is for local data storage or in iCloud. It takes care of all the persistence business. It does however not provide a means for storing data on your own db server.
For storage in Postgres or many other db, Vapor provides an ORM that is easy to handle.
The Swift-Vapor/Fluent stack has the advantage of being fully FOSS on the server side.
The client app has SwiftUI as a proprietary addition.