NSURL into NSData (Cocoa error 256.)

前端 未结 3 2091
逝去的感伤
逝去的感伤 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: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.

提交回复
热议问题