I want to have the pk in my fetched objects, so i can use the unique pk number for a unique image filename.
But i can't make it work, i just need a unique filename for my images. Does somebody has a solution for this?
When i NSLog object ID i get this:
NSManagedObjectID *ID = [someThing objectID]; NSLog(@"ID: %@",ID);
Output: ID: 0x124dd00
I know the last p11, resembles the pk, but whats the best way to get to it??
Instead of using the objectID which is not constant during the object's life cycle us can generate a unique UUID and store that as an attribute. The UUID can be generated as follows:
In a subclass of your managed object 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 that your attribute to store the UUID is called uuid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With