I found some code written in Swift on github,
And get a little confused about this line
var done: (NSError?, NSData, NSString?) -> () = { (_, _, _) -> () in } could you please explain the real meaning of this line? Thank you very much!
I found some code written in Swift on github,
And get a little confused about this line
var done: (NSError?, NSData, NSString?) -> () = { (_, _, _) -> () in } could you please explain the real meaning of this line? Thank you very much!
_ means don't name that thing. It can be used in a number of places. In your case, it is saying ignore the variable being passed into the closure. The code you gave is ignoring all parameters but you can also just ignore some parameters.
in is the start of the implementation of the closure. In your example code, the implementation of the closure is empty.
Overall, that line is defining a closure called "done" that takes an Optional NSError (NSError?), NSData (NSData), and Optional NSString (NSString?) and returns nothing (-> ()). The actual implementation of the closure does nothing.
done property, and the user of this Request class is expected to provide a closure that actually does something. In that closure, you'd provide local names for the parameters instead of using _ (as seen on what's currently line 55 in that gist).self as the delegate.
inspecifies the signature of the closure. It allows you to name the inputs parameters and also specify the output return type