Chris
Chris

Reputation: 21

Swift: Loading a large video file (over 700MB) into memory

I'm trying to load a large video file (over 700MB) into memory from the documents directory using let data: NSData = NSFileManager.defaultManager().contentsAtPath(path)! but it crashes my app. Smaller files load fine. Is there a better way to load larger files? Thanks.

Upvotes: 1

Views: 2438

Answers (1)

Ole Begemann
Ole Begemann

Reputation: 135578

Depending on what you want to do with the file, using NSData.init(contentsOfURL:options:) with the option .DataReadingMappedIfSafe may work for you.

This will map the file into memory (if possible), i.e. the file's contents will only be loaded (page by page) as you access them via the bytes property.

Upvotes: 6

Related Questions