Swift 2 beta: NSFileHandle(forReadingAtPath path: String) and forWritingAtPath missing throws?

Noticed that the read and write contructors for NSFileHandle throw when a NSURL is given but not when a path is given.


Is it that the throws is likely to be added in a future release?

Accepted Answer

That's because the Objective-C versions don't include an error return. Contrast:


+ (nullable instancetype)fileHandleForReadingAtPath:(NSString *)path;


and:


+ (nullable instancetype)fileHandleForReadingFromURL:(NSURL *)url error:(NSError **)error NS_AVAILABLE(10_6, 4_0);


There's not much that Swift can do about this.


* * *


As an aside, I encourage folks to use file URLs rather than paths. There are a couple of situations where using a path drops useful information. Most of these are irrelevant on iOS, but it's still best practice to use file URLs everywhere.


Share and Enjoy

--

Quinn "The Eskimo!"

Apple Developer Relations, Developer Technical Support, Core OS/Hardware

Swift 2 beta: NSFileHandle(forReadingAtPath path: String) and forWritingAtPath missing throws?
 
 
Q