Starting a new project recently and:
- Wading in to the SwiftData waters and added saving to a context, and I’m impressed. Gave the app an infinite loop at the view layer and we’ll fix that later.
- Doodled a couple candidates for a development and alternate app icon! Someone has to bring a little culture.
- Just that tiny bit of progress today but the momentum is what’s important.
Little clean-ups and place setting / writing plans for the next improvements:
- Fixed that loop lol
- Switched from dataTask completion handlers to Combine's dataTaskPublisher
- TIL don't use @Model var id
because that field name is already taken
- Hm that's weird though, the docs say it's persistentModelId
but Xcode 15.0.1 gives me id
in the definition.
- https://developer.apple.com/documentation/swiftdata/persistentmodel/persistentmodelid
Today:
- Added a preview for the first Form view
- Fixed preview for main view (need to add mock user data)
- Writing notes to connect model work with submitting this form
- Took a detour to build out fetching account info and then returned to pre-populate the form
- Hit a 401 when requesting account info
- Figured out I need to use the accessToken from the token body response
- Pre-filled that info on the form
- Display user's name on main page
- Lots more // TODO
Tonight:
- Added more data types
- Added more Form UI
- Moved Form State vars into actual model
- Picker
I am doing _something_ wrong that's crashing my Previews.
I have an @Observable class Client
that accepts SwiftData.ModelContext as various function parameters. Client is passed through @State/.environment(client)
.
My view will invoke client.doWork(modelContext) and that works well enough when running but something completely implodes in Previews. Doing any access on SwiftData.query and/or this Environment(Client.self) is wrecking this preview.
TIL about @Bindable which works with @Observable objects https://developer.apple.com/documentation/swiftui/bindable
Today
- No luck with my previews yet (likely have to mock out API client)
- add parsing/serializing idempotency test to main model (failing)
- add suggestions list for Manufacturer field with network fetch and SwiftData storage (pretty useful!) (more work to connect selection to main model)
- add KeychainSwift dependency
- add AuthenticatedUser (new) owns User (existing)
- add keychain caching for OAuth token — auto-login if the session is still valid!