Re:Swift – observations from Rust’s original designer
by mercutio2 on Tuesday June 03, 2014 @01:41AM
(#7838327)
> and there doesn't seem to be a way to define optional method parameters
Did you miss the part about default values?
If you're calling an Objective-C selector with more than one argument, you are indeed using an external parameter name, but external parameters are explicitly not required if you're writing pure Swift.
https://developer.apple.com/library/prerelease/ios/documenta...
Re:Swift – observations from Rust’s original designer
by kennywinker on Wednesday June 04, 2014 @06:28PM
(#7848819)
Oh cool, I definitely missed that!
I'm still playing with this but there are some interesting/weird things in here. What follows is a bunch of random observations of how named params work in Swift / ObjC. For instance:
Can be shortened using a pound symbol, because the variable name within the method, and the parameter name are the same thing: It also seems that most of the Cocoa APIs follow a convention, when called from Swift, of having an unnamed first parameter, and a named second parameter. e.g. this: becomes: which means it's called like so: If you name a parameter, you have to use the name. The order of parameters matters, and there doesn't seem to be a way to define optional method parameters (make sense as parameter names are essentially ObjC "selectors").