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
As always, keep a good proxy in your tool kit. I figured out the token issue way faster with Proxyman’s Compose Request tool.
At first I thought it might be cookies but changing those to match between iOS and web behaved the same. Then I realized that working requests on the web were using the accessToken value from the /token body instead of the value returned in the initial /authorize response.
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