Closed JaidynBluesky closed 1 year ago
Hey @JaidynBluesky! Your code is pretty close, instead of storedUser.set(newUser)
you should be calling $storedUser.set(newUser)
.
If you're familiar with property wrappers, the wrappedValue
is an Item
, but the projectedValue
is a StoredValue<Item>
. That means that when you access storedUser
the item you're interacting with is of type Item
, but the projected value is the one that contains all of the functions, including set()
and reset()
.
This follows similar conventions to @Published var items: [Item]
would let you use items
as a regular [Item]
, but $items
projects AnyPublisher<[Item], Never>
so you can subscribe to changes items
produces. Within Boutique the @Stored
property wrapper works very similarly.
Hope that clears things and lemme know if it works! I'll make sure to add some documentation inline above the set()
and reset()
functions, and have taken a note down to explain this in the walkthrough for @StoredValue
.
Ah, that would be why it's not working! 😄
edit: this works.
Preface: we were chatting on Twitter yesterday about the .documentsDirectory issue. I've switched to branch 2.0 and am trying some stuff out, so I understand the documentation isn't complete yet. :)
I have initialised a
@StoredValue
in one of my services like so:where
UserModel
isCodable
,Equatable
andIdentifiable
.From the existing file documentation, it seems like I just need to call
but that is giving me the following errors:
I've also tried awaiting the .set() function, but that doesn't solve it either.
Many thanks!