Hey, does anyone know why the wildcard (underscore) was used in setImage(_:forKey:)
?
let _ = try? data.write(to: url, options: [.atomic])
Writing it without let _
has it working just fine.
Hey, does anyone know why the wildcard (underscore) was used in setImage(_:forKey:)
?
let _ = try? data.write(to: url, options: [.atomic])
Writing it without let _
has it working just fine.
You can find the answer in Function Parameters and Return Values in the language manual The Swift Programming Language (Swift 4).
It is important that you first read that manual cover to cover a few times if you are not doing it already.
I have read the manual, thank you very much. write(to:options:)
does not have a return value.
Upon further research, it actually has to do with handling errors without do-catch. From Error Handling in the Swift manual:
You use try? to handle an error by converting it to an optional value. If an error is thrown while evaluating the try? expression, the value of the expression is nil.
For some reason, we do not care if the write is successful or not, but using try?
returns either an Optional
or nil
. Previously, Xcode would give a warning of an unused result, hence the use of the wildcard. However, as of Xcode 8 and Swift 3, you can safely write try? data.write(to: url, options: [.atomic])
without the wildcard.