Is it possible to fetch the number from the Z_PK column created by Core Data? If so, would you fetch this column the same way you would fetch attributes you created manuall
You could use sqlite to directly access the columns created by CoreData.
However, you shouldn't depend on Z_PK or any of the columns to stay consistent. The schema could change (and has) between releases. Apple has stated this in WWDC videos.
ios read z_pk from sqlite coredata
See this link to know more. As I know, we can't fetch Z-PK from core data. But you can know it by saving core data file like sqlite file and you can check it by query.
The z_pk is not an attribute that you can fetch like any other the other attributes. What you can do is to extract the z_pk value from the managedObjectID
of your entity
The managedObjectID can be obtained using [self objectID]
. For this example we take this one:
<x-coredata://03C5C895-3245-4D0F-8B6B-7758582AE16B/<your-Entity>/p5>
The p5
at the end is the z_pk. (For this store, and for this entity, at at this time. It can change)
Not sure what you need the z_pk for, nor in what format. Let's convert the managedObjectID
into a string:
NSString *aString = [[[self objectID] URIRepresentation] absoluteString];
From the string extract the 5
:
NSArray *theComponents = [aString componentsSeparatedByString:@"/p"];
NSInteger theZpk = [[theComponents lastObject] intValue];
Now you have the z_pk as an int
and can process it as you like.