MagicalRecords import data from JSON / NSDictionary. Import relationships

前端 未结 2 595
感情败类
感情败类 2021-01-07 11:41

I have questions with relationships. I have to NSManagedObject classes Team and Player. Team can contain many players. Player can contain only one team.

Here is the

2条回答
  •  情歌与酒
    2021-01-07 12:00

    I solved this problem one thing I miss was mappedKeyName for the Relationship's user info.

    At first we need to set mappedKeyName for the relationship that corresponds to the JSON key.

    So in case if JSON you got looks like below:

    {
        "status": 1,
        "message": "success",
        "player": {
            "playerID": 1,
            "teamID": 14,
            "firstname": "NAME",
        }
    }
    

    mappedKeyName key will be player.teamID

    relatedByAttribute key will be teamID that is an attribute of the Team entity.

    Hope it helps someone.

    enter image description here

提交回复
热议问题