Swift Method Parameter Names are Not Required, Illegal, and Inconsistent

Originator:PaulSolt
Number:rdar://17735653 Date Originated:7/18/14
Status:Open Resolved:No
Product:iOS Product Version:Xcode 6 Beta 3
Classification:UI/Usability Reproducible:Always
 
Summary:
It's a syntax error to include some method parameters for some APIs and not others. It makes it very hard to know when you need to do it and when you can't.

This needs to be standard and one style needs to be chosen for the APIs, it's not consistent.

I struggled to write my first line of code because I couldn't figure out why my parameter names worked in some functions and didn't in others.

let tableView = UITableView(frame: CGRect(x: 0, y: 0, width: 320 height: 300))

vs.

tableView.dequeueReusableCellWithIdentifier("cell")

Steps to Reproduce:
Try to write

tableView.dequeueReusableCellWithIdentifier("cell")

with the parameter name

tableView.dequeueReusableCellWithIdentifier(identifier:"cell") // Error!

why?

Expected Results:
Both should work.

Actual Results:
Error on 2nd line. Super confused. Why?



Version:
Xcode 6 Beta 3

Notes:
Doesn't make sense coming from Objective-C code, and inconsistent behavior means the user needs to memorize methods that work with parameter names and methods that don't.

It should work either way, or it should work only one way.

Configuration:
Mavericks

Attachments:

Comments

I agree with your sentiment, but you hardly have to memorize anything. The Swift book explains it:

  • in initializers, all arguments have labels by default
  • in methods, all arguments, except for the first one, have labels by default
  • in functions, arguments don't have any labels by default.

Besides, Xcode has code suggestions.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!