Search code examples
iosfileswiftnsdictionaryplist

plist attachment from email in swift (NS Cocoa Error Domain Code 260)


I am sending some ios file data via an email contained in a plist. No issues attaching it, I can check the file and the contents. It's all there and I can open it as a plist. Clicking on it (I have associated it with my app) it opens and I get a valid path:

file:///private/var/mobile/Containers/Data/Application/C5454580-2BEB-4515-9BDE-FED85FF54F76/Documents/Inbox/ShareStrength-11.bps

that I pass but when I try and read back the NSDictionary (plist) I get nil content.

let sourceFile = NSDictionary(contentsOfFile: URLString)

Any ideas on what is going wrong. Having difficulty debugging.

EDIT: I found some error code:

var error: NSError?
let content = NSString(contentsOfFile: URLString, encoding:NSUTF8StringEncoding, error: &error)
if content != nil
{
    println("content: \(content)")
}
else
{
    println("error: \(error)")
}

And I get the error:

error: Optional(Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x17eceeb0 {NSFilePath=file:///private/var/mobile/Containers/Data/Application/571DB0FF-6C5A-4BEB-9FA8-6E4DFE10E850/Documents/Inbox/ShareStrength-13.bps, NSUnderlyingError=0x17ee9810 "The operation couldn’t be completed. No such file or directory"})

Is this a sandbox issue? How can I copy the attachment being passed as a URL?


Solution

  • I was using:

    let URLString: String = url.absoluteString!
    

    instead of:

    let URLString: String = url.path!
    

    Hope this helps someone else