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
NSURL
NSData
// Given some file path URL: NSURL *pathURL // Note: [pathURL isFileURL] must return YES NSString *path = [pathURL path]; NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
Swift code:
let data = FileManager.default.contents(atPath: path)