Core data 如何查看ObjectId

ObjectId是Core Data 为每一个数据对象提供的唯一ID标识,获取ObjectID、并打印的方法如下:

步骤:

1. 获取ManagedObject

2. ManagedObject -> ObjectID

3. ObjectId -> URL

4. URL -> String

        NSManagedObject *managedObject = youManagedObject;//取得Object对象指针
        NSManagedObjectID *objId = [managedObject objectID];//获取ObjectId
        
        NSURL * uri = [objId URIRepresentation];//ObjectId - > URL
        NSString *s = [uri absoluteString];//URL - > String
        
        NSLog(@"uri = %@", s);//打印ObjectId 对应的String

 

结果实例

uri = x-coredata://8FA76F17-3846-4801-B398-80EE9E13EA14/Event/p1

uri = x-coredata://8FA76F17-3846-4801-B398-80EE9E13EA14/Event/p2

uri = x-coredata://8FA76F17-3846-4801-B398-80EE9E13EA14/Event/p3

 

posted @ 2015-08-13 00:08  明明1109  阅读(748)  评论(0编辑  收藏  举报