Xcode 6.1: Swift method declaration syntax is inconsistent with actual call syntax

Originator:kusterer
Number:rdar://18703915 Date Originated:19-Oct-2014 09:32 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.1 (6A1042b)
Classification:UI/Usability Reproducible:Always
 
When calling a Swift method, one writes it as:

userNotificationCenter( foo, didDeliverNotification: bar)

However, the declaration is

optional func userNotificationCenter(center: NSUserNotificationCenter, didDeliverNotification notification: NSUserNotification)

Note how the colon is in a different spot, kind of overloaded. It would be easier to remember this syntax if it was closer to the actual call syntax. I recommend just adding an additional colon after the label. The comma can be used to detect the end of a parameter in the case of the first parameter, to detect that it’s not a label here.

Alternately, one could always have the additional comma, and permit ObjC-style “empty” parameters:

optional func userNotificationCenter( : center: NSUserNotificationCenter, didDeliverNotification: notification: NSUserNotification)

This would make it much more obvious what is a label, and what is a parameter name followed by a colon and a type.

Comments


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!