JRo
JRo

Reputation: 163

Z_PK Column in Core Data Database

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 manually in the model?

Upvotes: 2

Views: 3376

Answers (3)

Olaf
Olaf

Reputation: 3042

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 managedObjectIDof 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.

Upvotes: 6

Kevin
Kevin

Reputation: 3131

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.

Upvotes: 4

Nguyen Thi Thuy Trang
Nguyen Thi Thuy Trang

Reputation: 204

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.

Upvotes: 0

Related Questions