NSManagedObjectID into NSData

前端 未结 6 2128
一生所求
一生所求 2020-12-30 06:27

I found this wonderful NSManagedObjectID. This would be very good for referencing an Entity/NSManagedObject/NSEntityDescription, right?
Let\'s get an ID from an entity:<

6条回答
  •  隐瞒了意图╮
    2020-12-30 07:13

    As @preston said, don't save an objectID to disk, instead:

    1. Make a new attribute on your entity called "id"
    2. Make a new attribute on your entitys parent entity called "myEntitysMaxId"
    3. Override your entitys parent implementation "addNewMyEntityObject:"
    4. There, increase "myEntitysMaxId" and set that value as the new entitys "id"
    5. Do as you normally do when you fetch an entity based on its attributes!

    Much cleaner and better!

提交回复
热议问题