Question

A core data objectID looks like this:

x-coredata:\/\/6CBBA433-7B21-4638-BBBD-67C771B38E97\/User\/p2

How can I retrieve in an easy, pretty way the last sequence number?

Was it helpful?

Solution

You can't, at least not if you want reliable, stable code. Getting the end of that string is basic string processing. It's the last component of a URL, there's even a method on NSURL that will just give it to you.

But the format of these ID strings is undocumented, and therefore something that can potentially change any old time Apple thinks it would be a good idea. You'd be relying on something which is in no way guaranteed to actually work.

If you want a sequence number, add a sequence number as one of the attributes of the object. That's the right way to do it with Core Data. Not only is it more reliable, it's something you can change when or if you think it should change instead of being something Apple will break for you when they think it should change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top