wvteijlingen / Spine

A Swift library for working with JSON:API APIs. It supports mapping to custom model classes, fetching, advanced querying, linking and persisting.
MIT License
264 stars 109 forks source link

No way to act on a resource being saved #122

Closed Cbieniak closed 7 years ago

Cbieniak commented 7 years ago

Currently we have a situation where we want to persist an objects data to keychain if it has a authtoken, but we don't have an attribute that is called on completion of the mapping of values.

I was wondering if you saw this action a responsibility of the future. Possibly with all Resources conforming to a didFinishMapping protocol and the success future calling it. Or a resource responsibility where it keeps track itself and acts once it knows all attributes have been mapped.

wvteijlingen commented 7 years ago

When the onSuccess callback fires, mapping of values has finished. But I guess you mean some callbacks in the Resource class itself. I've thought about adding that at some point, but never really had a use case for it myself yet.

Perhaps you can use Key Value Observing to achieve this in the meantime.

Cbieniak commented 7 years ago

thank you for the reply.

We've decided to manually do these actions on specific endpoints and it turns out having it as a callback would have probably been overkill anyway.

wvteijlingen commented 7 years ago

Good to hear this is solved for you :).