Oddbean new post about | logout
 GM! I’m finding SwiftData to be a bit difficult to work with, too. Are you using value transformers? For the time being, I’m using SwiftData as a semi-dumb data store for Nostr event kinds and local app settings, and I load everything into my in-memory cache on app launch. I hope to integrate more closely to SwiftData as Apple improves it over time. 
 I haven't used value transformers before.  Im going to look into them though.

Right now I have a handful of models that I create from events as they come in, then store them into SwiftData, but that code is getting overly complicated. So before I dig too deep Im experimenting with something that may or may not work.

Instead of having all these different SwiftData models, Im simply storing a single model for the event. Almost as it would be stored on a relay. One addition to the model is that I serialize the tags into a single special formatted string since trying to use a predicate on nested arrays might get messy.

The idea is that this keeps my data model more simple as well as code path where I store these events.

Then I will use the queries to map the stored event's into their more detailed object where needed.

The unknown I have now is if doing this will cause too much overhead on the UI. I just don't know yet, but my code is early enough that I can try it and if it works as I hope it does it simplifies the code around this a lot. 
 Sounds similar to what I’m doing with the storage part. I store the serialized JSON of the Nostr event (and use a value transformer to get the deserialized object) and which relays the event was found into a single model. Then I map those to specific event kind classes on app launch.