iPhone - NSData from local file's URL

Viewed 77769

I have a NSURL object which gives me the path of a local file (in documents folder). I want to populate an NSData object with the contents of this file. Tried using dataWithContentsOfURL: but this fails. I know the file exists because the iPhone SDK returns the path.

Can someone please tell me how I can get an NSData object from the URL of a local file?

Thanks.

5 Answers
guard let data = FileManager.default.contents(atPath: path) else
    { ...
Related