Z_PK Column in Core Data Database

后端 未结 3 1239
暖寄归人
暖寄归人 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 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:

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

提交回复
热议问题