Xcode Beta 6 Function types cannot have argument label

This started in the new Beta 6 of Xcode.


typealias DatePickerCellUpdateBlock = (calendar: Calendar, date: Date, locale: Locale?, timeZone: TimeZone?) -> Void


Produces:

Function types cannot have argument label 'calendar'; use '_' instead

Function types cannot have argument label 'date'; use '_' instead

Function types cannot have argument label 'locale'; use '_' instead

Function types cannot have argument label 'timeZone'; use '_' instead

I now have over 100 of these. Worked fine in Beta 5 and ealier.

Anyone else getting these or know how to fix it in the advent I missed a change to the syntax?

Thanks,

Rob

Answered by guywithmazda in 169342022

This is discussed in the release notes.

Accepted Answer

This is discussed in the release notes.

can anyone explain why?


This seems to be the opposite direction to what has been taken elsewhere with labels being the default.

I'm not clear why the argument would be different in this case.


why is


completion(myImage)

better than


completion(image:myImage)


in the case of closure, but not in a method call...

It is discussed here: https://github.com/apple/swift-evolution/blob/master/proposals/0111-remove-arg-label-type-significance.md


Not sure I agree with they way they decided to handle it though. Seems more confusing without labels.

Yep, I don't quite understand this one either.


SE-0111 has more details on this:

https://github.com/apple/swift-evolution/blob/master/proposals/0111-remove-arg-label-type-significance.md


Writing out a function type containing argument labels will be prohibited:

// NOT ALLOWED

let fn3 : (a: Int, b: Int) -> Bool


// Must write:

// let fn3 : (Int, Int) -> Bool


I really don't want the second example for my stored completion handlers.


Here is a workaround. I don't like it but it's better than not using label names.

https://twitter.com/spaxeon/status/765330050233298944

The Swift Evolution list has the whole discussion, as well as the change they made at the end of the process:


https://lists.swift.org/pipermail/swift-evolution-announce/2016-July/000233.html

Seems like a big change late in the life of the beta. And seems like correcting a minor edge case, while loosing a lot of readability. Much of Apple's own Swift 3 sample code won't compile now...

I couldn't agree more Steven!

I completely agree with your assessment, they seem to have decided that it's more important to allow swapping arbitrary functions with the same parameter types around instead of being able to reason about the code and avoid bugs. O_o

I agree 100%.

100% agree. This is a long pass late in the game in order to project some obtuse "Core Team" vision of Swift 4 parameter typing/naming (a vision on which the 'community' has not even come to any kind of agreement or had any real discussion).


Sadly, as has remained consistently true for a decade+, Apple "Community Process" == Apple "Does-Whatever-It-Wants"

Completely agree. I've had a moan recently about how much has changed so late in the cycle. It should have been in Swift 3.1 or 4 at this point in my opinion.

I got a similar issue...



typealias ServerCallbackType = (AnyObject?, NSError?) -> Void

let followBlock = { (returnBlock: @escaping ServerCallbackType) -> () in

}

//I NEED TO CAST THE BLOCK HERE... but the compiler should already know it...

cell.configureBlocks(followBlock: followBlock as! ((AnyObject?, NSError?) -> Void) -> (), ...

Am I doing something wrong?

Xcode Beta 6 Function types cannot have argument label
 
 
Q