views:

81

answers:

2

Hello,

I have some data that I export into an XML file and put in a remote FTP Server.

I have to identified each object with a unique attribute, it doesn't matter wich is, but must be persistent always => it can never change.

I don't want to create a unique attribute, sequence, serial, etc.

I'm using the objectID but every time I use it a get a new reference.

I know that before the object has been saved, it has a 'temporal id', but once it's saved, it gets the definitive.

I'm not seeing this, never.

When I export, just fetch all data and loop, and always I get a new reference:

NSURL *objectID = [[personalDataObject objectID] URIRepresentation];

// some of id received for the SAME OBJECT (no changes made, saved, ...)
// 61993296
// 62194624

thanks,

r.

edit

I was using %d instead of %@, now the returned data is:

x-coredata://F46F3300-8FED-4876-B0BF-E4D2A9D80913/DataEntered/p1
x-coredata://F46F3300-8FED-4876-B0BF-E4D2A9D80913/DataEntered/p2
A: 

I think this maybe a reporting problem. The numbers you show that are supposed to be a URI/UUID are way, way to short.

They should look like:

UUIDs (Universally Unique Identifiers), also known as GUIDs (Globally Unique Identifiers) or IIDs (Interface Identifiers), are 128-bit values guaranteed to be unique. A UUID is made unique over both space and time by combining a value unique to the computer on which it was generated—usually the Ethernet hardware address—and a value representing the number of 100-nanosecond intervals since October 15, 1582 at 00:00:00.

The standard format for UUIDs represented in ASCII is a string punctuated by hyphens, for example 68753A44-4D6F-1226-9C60-0050E4C00067. The hex representation looks, as you might expect, like a list of numerical values preceded by 0x. For example, 0xD7, 0x36, 0x95, 0x0A, 0x4D, 0x6E, 0x12, 0x26, 0x80, 0x3A, 0x00, 0x50, 0xE4, 0xC0, 0x00, 0x67 . To use a UUID, you simply create it and then copy the resulting strings into your header and C language source files. Because a UUID is expressed simply as an array of bytes, there are no endianness considerations for different platforms.

I think you're seeing different values because your only getting a piece, and a different piece at that, each time you check the UUID. Represented as a URI, they should look more like a URL. They definitely won't look like an integer.

TechZen
ok, maybe the problem is when I take the value of the URIRepresentation, I'm going to check again and post again! thanks
mongeta
@mongeta: Are you using `%d` instead of `%@` in your `NSLog` function? If so, then you'll see the memory address of the URL, rather than the string representation.
eman
oh man, how can I be so stupid ????? :-)I was using %d instead of %@
mongeta
+1  A: 

The NSManagedObjectID is not guaranteed to be consistent. It can change based on a number of factors including data migration and other factors. If you are using this as a unique identifier for your objects, stop.

The only time you want to use the NSManagedObjectID is when you need to pass references between threads. Other than that situation you should not rely upon it for anything.

If you need a unique id then create one and store it in your entities.

Marcus S. Zarra