Skip to content

Update NSManagedObject with JSON #72

Description

@ManueGE

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions