-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement -[NSData writeToURL:options:error:] #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement -[NSData writeToURL:options:error:] #57
Conversation
public func writeToURL(url: NSURL, options writeOptionsMask: NSDataWritingOptions) throws { | ||
NSUnimplemented() | ||
if let path = url.path { | ||
do { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is no need for do {} catch {}
blocks, you can simply use try writeToFile(path, options: writeOptionsMask)
Check only for the existence of file owner's account (user) identifier instead of comparing its numeric value because - user identifier of `0` are assigned to the superuser in linux - negative value are valid account identifier. e.g. `nobody` is `-2` (See https://en.wikipedia.org/wiki/User_identifier) - There's an assumption made here that account identifier are numeric which is reasonable for most system but there's a slim chance that this might not be the case. Thanks to @lxcid
Add string constants for NSDecimalNumber Add more string constants Add more string constants
- verify that URL is a file path, and do it early - remove unnecessary do/catch Thanks so much for the feedback, @ookla and @johankool!
public func writeToURL(url: NSURL, options writeOptionsMask: NSDataWritingOptions) throws { | ||
NSUnimplemented() | ||
guard let path = url.path where url.filePathURL == true else { | ||
let userInfo = [NSLocalizedDescriptionKey : "The folder at “\(url)” does not exist or is not a file URL.", // NSLocalizedString() not yet available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that the error message also isn't quite correct about the first part. You aren't checking whether a folder exist, but wether the URL given contains a path. (But I am not sure exactly what the existing Foundation framework does/reports in this case.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the url is a file url then it checks to see if the url has a path, if it does not it claims there is no such file (which is kind-of true-ish)
then it will funnel to writeToFile in the case of a file url (which has it's own error cases)
else it claims the url is an unsupported scheme.
@lowell I'll take you up on your offer to close this one and rebase so we don't get things really confused. |
Oops, didn't mean to close it myself. Close when you're ready. |
Thanks @parkera. :D Resubmitted. |
Correct location property of DiagnosticRelatedInformation
[pull] swiftwasm from master
I feel like I should feel bad for submitting a PR during a weekend, but this is fun.