Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NSManagedObject with JSON #72

Open
ManueGE opened this issue Sep 27, 2016 · 0 comments
Open

Update NSManagedObject with JSON #72

ManueGE opened this issue Sep 27, 2016 · 0 comments

Comments

@ManueGE
Copy link

ManueGE commented Sep 27, 2016

Hi,

In the projects where I use Groot, very often I need to update existing objects that has not (yet) a primary key using a given JSON.

As an example, let's think I can create a Character from my app and send to my server. The Character I created has not a primary key, because that key is provided by the server after being pushed. It would be great if once the Character is pushed I can use the response from my server to update it:

let character = Character(context: managedObjectContext)
character.name = "Batman"
character.realName = "Bruce Wayne"

character.pushToServer { json in // the json is: {"id": 1, "name": "Batman", "real_name": "Bruce Wayne"}     
    character.update(with: json)
    // now, character.id = 1 
}

I usually solve it by creating a NSManagedObject category that provides this functionality, basically exposing one private method. I wonder if it would make sense adding such functionality to the official release. If so, I could prepare a pull request.

Any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant