没有主键的MagicalRecord导入

时间:2014-01-09 23:22:27

标签: ios objective-c magicalrecord

有没有办法导入没有primaryKeyrelatedByAttribute的魔法记录数据?

我的JSON看起来像这样。如您所见,这是员工也可以访问的服务列表。我也没有唯一的身份证明。

{
   "status":0,
   "statusMessage":"Call success",
   "details":{
      "items":[
         {
            "status":0,
            "statusMessage":"Employee service schedule list returned",
            "details":{
               "itemsReturned":2,
               "items":[
                  {
                     "clientId":747,
                     "employeeId":2241,
                     "serviceId":3137,
                     "duration":60,
                     "scheduleMondayStartTime":480,
                     "scheduleMondayEndTime":1020,
                     "scheduleTuesdayStartTime":480,
                     "scheduleTuesdayEndTime":1020,
                     "scheduleWednesdayStartTime":480,
                     "scheduleWednesdayEndTime":1020,
                     "scheduleThursdayStartTime":480,
                     "scheduleThursdayEndTime":1020,
                     "scheduleFridayStartTime":480,
                     "scheduleFridayEndTime":1020,
                     "scheduleSaturdayStartTime":null,
                     "scheduleSaturdayEndTime":null,
                     "scheduleSundayStartTime":null,
                     "scheduleSundayEndTime":null
                  },
                  {
                     "clientId":747,
                     "employeeId":7178,
                     "serviceId":3137,
                     "duration":60,
                     "scheduleMondayStartTime":480,
                     "scheduleMondayEndTime":1020,
                     "scheduleTuesdayStartTime":480,
                     "scheduleTuesdayEndTime":1020,
                     "scheduleWednesdayStartTime":480,
                     "scheduleWednesdayEndTime":1020,
                     "scheduleThursdayStartTime":480,
                     "scheduleThursdayEndTime":1020,
                     "scheduleFridayStartTime":480,
                     "scheduleFridayEndTime":1020,
                     "scheduleSaturdayStartTime":null,
                     "scheduleSaturdayEndTime":null,
                     "scheduleSundayStartTime":null,
                     "scheduleSundayEndTime":null
                  }
               ]
            }
         },
         {
            "status":0,
            "statusMessage":"Employee service schedule list returned",
            "details":{
               "itemsReturned":2,
               "items":[
                  {
                     "clientId":747,
                     "employeeId":2241,
                     "serviceId":3138,
                     "duration":5,
                     "scheduleMondayStartTime":480,
                     "scheduleMondayEndTime":1020,
                     "scheduleTuesdayStartTime":480,
                     "scheduleTuesdayEndTime":1020,
                     "scheduleWednesdayStartTime":480,
                     "scheduleWednesdayEndTime":1020,
                     "scheduleThursdayStartTime":480,
                     "scheduleThursdayEndTime":1020,
                     "scheduleFridayStartTime":480,
                     "scheduleFridayEndTime":1020,
                     "scheduleSaturdayStartTime":null,
                     "scheduleSaturdayEndTime":null,
                     "scheduleSundayStartTime":null,
                     "scheduleSundayEndTime":null
                  },
                  {
                     "clientId":747,
                     "employeeId":7178,
                     "serviceId":3138,
                     "duration":5,
                     "scheduleMondayStartTime":480,
                     "scheduleMondayEndTime":1020,
                     "scheduleTuesdayStartTime":480,
                     "scheduleTuesdayEndTime":1020,
                     "scheduleWednesdayStartTime":480,
                     "scheduleWednesdayEndTime":1020,
                     "scheduleThursdayStartTime":480,
                     "scheduleThursdayEndTime":1020,
                     "scheduleFridayStartTime":480,
                     "scheduleFridayEndTime":1020,
                     "scheduleSaturdayStartTime":null,
                     "scheduleSaturdayEndTime":null,
                     "scheduleSundayStartTime":null,
                     "scheduleSundayEndTime":null
                  }
               ]
            }
         },
         {
            "status":0,
            "statusMessage":"Employee service schedule list returned",
            "details":{
               "itemsReturned":1,
               "items":[
                  {
                     "clientId":747,
                     "employeeId":7178,
                     "serviceId":3139,
                     "duration":15,
                     "scheduleMondayStartTime":480,
                     "scheduleMondayEndTime":1020,
                     "scheduleTuesdayStartTime":480,
                     "scheduleTuesdayEndTime":1020,
                     "scheduleWednesdayStartTime":480,
                     "scheduleWednesdayEndTime":1020,
                     "scheduleThursdayStartTime":480,
                     "scheduleThursdayEndTime":1020,
                     "scheduleFridayStartTime":480,
                     "scheduleFridayEndTime":1020,
                     "scheduleSaturdayStartTime":null,
                     "scheduleSaturdayEndTime":null,
                     "scheduleSundayStartTime":null,
                     "scheduleSundayEndTime":null
                  }
               ]
            }
         }
      ]
   }
}

使用没有唯一ID的魔法记录导入这些内容的最佳方法是什么?

1 个答案:

答案 0 :(得分:2)

MagicalRecord导入仍然可以使用此数据。由于您通过json密钥获得了相关对象,因此我们可以知道您希望将核心数据实体与之相关联。此外,只要您正确地将json属性映射到核心数据属性,这也为导入库提供了足够的信息,以确定与导入内容相关的内容。