NSURL in NSData (Cocoa Error 256.)

I need to serialize my NSURL.

object - the type of the NSManagedObject object.

NSURL *objectURIRepresentation = [[object objectID] URIRepresentation];
NSError *error = nil;
NSData *objectIDData = [NSData dataWithContentsOfURL:objectURIRepresentation options:NSDataReadingMapped error:&error];

I get the error: (Cocoa error 256.). Any ideas? Something tells me that using dataWithContentsOfURL:is not a good idea.

Update

Another question that is mistakenly posed as a comment:

What is the difference between [NSData dataWithContentsOfURL:uri];and [NSKeyedArchiver archivedDataWithRootObject:uri];?

Thank.

+5
source share
3 answers

First, your code is not trying to serialize the NSURL object; it is trying to create a data object from the data at the URL returned as the URI of the managed object.

Secondly, it will never work.

[NSData dataWithContentsOfURL:] URL-. URI , , SQLite.

URI . URI - , .

NSManagedObject NSCoder, . , , .

+4

Cocoa 256
256 , .

, NSManagedObject. , @fluchtpunkt http://cocoawithlove.com/2008/08/safely-fetching-nsmanagedobject-by-uri.html

, , [NSData dataWithContentsOfURL:uri]; -url . [NSKeyedArchiver archivedDataWithRootObject:uri]; NSData, , .

+4

"Http://"

+2
source

All Articles