Friday, March 29, 2019

The Weirdness of NSURL’s isDirectory Flag

Brian Webster:

Cocoa Protip: Using +[NSURL fileURLWithPath:] hits the filesystem and can cause slowdowns. Use +[NSURL fileURLWithPath:isDirectory:] instead. Same goes for -[NSURL URLByAppendingPathComponent:isDirectory:]

Peter Hosey:

I don’t remember if it’s documented [It is. —Michael] but it’s true (observable in Instruments/sample). If you don’t tell it whether the thing is a directory, it will go find out, immediately.

I’m well aware of this because it’s caused significant performance issues for me when dealing with large numbers of files. However, it’s not clear to me why it works this way:

Previously:

Comments RSS · Twitter

Leave a Comment