Post

Replies

Boosts

Views

Activity

Data (contentsOf: url, options: .alwaysMapped) doesn't 'map' in Xcode 10.2/Swift 5
I've found that when I try to access a huge (several Gigabyte ,eg. a movie) file in an application compiled with Swift 5 / XCode 10.2, it no longer 'maps' the file. Instead, it loads the entire thing - which causes my application to hang for several seconds.The file is a local file, so it should be able to map it fine.I was so suprised that I created a test app, the guts of it being...func openMappedFile (url: URL) throws { let data = try Data (contentsOf: url, options: .alwaysMapped) print (data.count) }Sure enough, when I compile the test app with XCode 10.1/Swift 4.2, it behaves as expected, and immediately prints the count of the number of bytes in the file - without having to load the entire thing.But when I compile the same app with XCode 10.2/Swift 5, it hangs for several seconds, with lots of disk activity while it loads the file before printing 'count'Has anyone else been affected by this? Does anyone know of a workaround (while still using 'Data' - I don't want to have to fiddle round with Darwin APIs, mmap, etc.). Or should I just go back to using XCode 10.1 until it's (hopefully) fixed. I've already raised a bug for this in Bug Reporter.
12
0
7.8k
Apr ’19