NSURL into NSData (Cocoa error 256.)

前端 未结 3 2090
逝去的感伤
逝去的感伤 2020-12-17 04:10

I need to serialize my NSURL.

object is type of NSManagedObject.

NSURL *objectURIRepresentation = [[object objectID] URIRepresentation];
NSError *err         


        
相关标签:
3条回答
  • 2020-12-17 04:14

    As mentioned here Cocoa error 256 core data
    error code 256 can occur when an unknown error is occurred in reading the resource or the path has some encoded characters in it.

    What it seems to me is you are trying to get the data from NSManagedObject. Hence as @fluchtpunkt suggested you should look for http://cocoawithlove.com/2008/08/safely-fetching-nsmanagedobject-by-uri.html

    Now coming to your second question [NSData dataWithContentsOfURL:uri]; returns data for a web url or a local resource in your documents directory. While [NSKeyedArchiver archivedDataWithRootObject:uri]; returns the NSData object containing the encoded form of the object graph whose root object is given.

    0 讨论(0)
  • 2020-12-17 04:31

    try to add "Http://" before in the link

    0 讨论(0)
  • 2020-12-17 04:38

    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.

    0 讨论(0)
提交回复
热议问题