Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the x-coredata path mean when I 'po' the core data object in lldb?

When I print an object description for a core data object in lldb I'll sometimes get the following object description:

(lldb) po my_challenge_object (entity: Challenge; id: 0x170433460 <x-coredata:///Challenge/t52BD558C-A8FE-4064-A8BE-217A837521E52> ; data: {...})

If I print the same object at a later time, I'll sometimes see the 'x-coredata' path change.

(entity: Challenge; id: 0x170433460 <x-coredata://50232AB5-7372-4628-9F00-51BDB1A5C96D/Challenge/t52BD558C-A8FE-4064-A8BE-217A837521E52> ; data: {...})

My question is, what does that path mean and why is it changing? What does the addition of '50232AB5-7372-4628-9F00-51BDB1A5C96D' tell me about my object, in this case?

like image 671
kross Avatar asked Jan 10 '14 08:01

kross


People also ask

What is Core Data in IOS?

Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence.

How do I use Core Data?

Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device. To sync data across multiple devices in a single iCloud account, Core Data automatically mirrors your schema to a CloudKit container.

What is managed object in Core Data?

A managed object context represents a single object space, or scratch pad, in a Core Data application. A managed object context is an instance of NSManagedObjectContext . Its primary responsibility is to manage a collection of managed objects.


1 Answers

When you first print the object it has not been assigned to a persistent store:

(lldb) po my_challenge_object
<Challenge: 0x1700da1d0> (entity: Challenge; id: 0x170433460 <x-coredata:///Challenge/t52BD558C-A8FE-4064-A8BE-217A837521E52> ; data: {...})

Thats why there are three slashes after the colon in the managed object ID.

In the second instance, it has been assigned to a persistent store with the identifier "50232AB5-7372-4628-9F00-51BDB1A5C96D".

<Challenge: 0x1700da1d0> (entity: Challenge; id: 0x170433460 <**x-coredata://50232AB5-7372-4628-9F00-51BDB1A5C96D/Challenge/t52BD558C-A8FE-4064-A8BE-217A837521E52**> ; data: {...})

The structure of a managed object ID URI is generally as follows:

x-coredata://[Store UUID]/[Entity Name]/[Primary Key]

Note: that the [Primary Key] section is store specific, and may refer to the pk of a sqlite row or some other identifier in an XML or Binary store.

The store UUID is available from the store's metadata dictionary, or by asking an instance of NSPersistentStore for its identifier:

NSLog(@"Store Identifier: %@", [store identifier]);
like image 53
ImHuntingWabbits Avatar answered Sep 21 '22 10:09

ImHuntingWabbits