I need to serialize my NSURL.
object is type of NSManagedObject.
NSURL *objectURIRepresentation = [[object objectID] URIRepresentation];
NSError *err
Firstly, your code does not attempt to serialize a NSURL object, it attempts to create a data object out of the data at the URL returned as the URI of a managed object.
Secondly, that is never going to work.
[NSData dataWithContentsOfURL:] will try to read a file at a particular URL. The URI of a managed object represents an object stored in pieces with many others inside a persistent file like a SQLite database.
The URI only allows a managed object context to identify a particular object in its own store. The URI is gibberish to anything else other than the context.
NSManagedObject does not implement the NSCoder protocol so managed objects cannot be serialized. I'm not sure what you want to do here but you can't do it this way.