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
时间: 2024-10-06 05:01:11