Z_PK Column in Core Data Database

后端 未结 3 1240
暖寄归人
暖寄归人 2021-01-01 07:13

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

相关标签:
3条回答
  • 2021-01-01 07:37

    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.

    0 讨论(0)
  • 2021-01-01 07:45

    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.

    0 讨论(0)
  • 2021-01-01 08:00

    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.

    0 讨论(0)
提交回复
热议问题