Instead of using an object identifier that is not constant during the life cycle of an object, we can create a unique UUID and save it as an attribute. UUID can be generated as follows:
In a subclass of your managed entity, add the following code to your awakeFromInsert:
- (void)awakeFromInsert; { [super awakeFromInsert]; CFUUIDRef UUID = CFUUIDCreate(kCFAllocatorDefault); CFStringRef UUIDString = CFUUIDCreateString(kCFAllocatorDefault,UUID); [self setValue:(NSString *)UUIDString forKey:@"uuid"]; [UUID autorelease]; [UUIDString autorelease]; }
This assumes your attribute for storing the UUID is called uuid.
source share