4 ms·
He doesn't seem to know much about iOS or Objective-C due to that comment about parameter names probably being unused. You wouldn't be able to make meaningful m
by lnanek2 12y ago
He doesn't seem to know much about iOS or Objective-C due to that comment about parameter names probably being unused. You wouldn't be able to make meaningful method selectors calling into the code from Objective-C without them, since the names of the parameters are part of the method name in Objective-C.
- kennywinker 12y agoMethod parameter names are used similarly in Swift as in ObjC. For example two methods can have the same name, as long as they have a difference set of parameters. For example: func methodName(paramName: String) and func methodName(paramName: String, otherParam: Int) are different. 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: func methodName(name name: String) Can be shortened using a pound symbol, because the variable name within the method, and the parameter name are the same thing: func methodName(#name: String) 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: -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath becomes: func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! which means it's called like so: myObject.tableView(tableView, cellForRowAtIndexPath: indexPath) 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").
- mercutio2 12y ago> 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/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html#//apple_ref/doc/uid/TP40014097-CH10-XID_213 https://developer.apple.com/library/prerelease/ios/documenta...
- kennywinker 12y agoOh cool, I definitely missed that!