I wish to possess the pk during my fetched objects, in order to make use of the unique pk number for any unique image filename.

However i can't have great results, i simply require a unique filename for my images. Does somebody includes a solution with this?

After i NSLog object ID i recieve this:

NSManagedObjectID *ID = [someThing objectID] NSLog(@"ID: %@",ID)

Output: ID: 0x124dd00

I understand the final p11, resembles the pk, but what is the easiest method to reach it??

Rather than while using objectID which isn't constant throughout the object's existence cycle us can produce a unique UUID and store that being an attribute. The UUID could be produced the following:

Inside a subclass of the handled object add the next code for 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 the attribute to keep the UUID is known as uuid.

sorry for that late reply :)

You can simply do (presuming as others have stated, the objectIDs happen to be permanent for the object):

[[[myManagedObject objectID] URIRepresentation] lastPathComponent]

... to obtain the "p28" part etc.

Hope this can help, Ken

You aren't getting direct accessibility SQL PK since that's an interior detail utilized by Compact disc to unique the objects and may change. You should use the NSManagedObjectID though:

- (NSURL *) uniqueURLForManagedObject:(NSManagedObject *)managedObject {
  NSManagedObjectID *objectID = managedObject.objectID;
  NSURL *objectURL = managedObject.URIRepresentation

  return objectURL;

After that you can take that URL utilize it like a file title. You most likely wish to take away the schema plus some other bits, but that is not necessary should you scribe the URL in a way it only has figures that legal in file names. Just make certain the object was already saved out if you do this or even the ID won't be a lasting ID (checkout NSManagedObjectID's documentation for additional particulars).

OKe thanks, now we all know i'm searching within the right direction!, after i NSLog my objects they appear the same, except the final bit.

ID1: x-coredata://5B58789C-70CE-40D7-B0BA-B9F56DEBFF61/Things/p28
ID1: x-coredata://5B58789C-70CE-40D7-B0BA-B9F56DEBFF61/Things/p27
ID1: x-coredata://5B58789C-70CE-40D7-B0BA-B9F56DEBFF61/Things/p26
ID1: x-coredata://5B58789C-70CE-40D7-B0BA-B9F56DEBFF61/Things/p25

Can't i simply skip part one and merely make use of the last bit for my filename. And so i have my files named like so:

p25 p26 p27 p28