[swift-evolution] [Pitch] Adding in Optional Argument labels for completion handlers

Grant Kemp grant at kempnet.com
Sun Oct 16 17:33:51 CDT 2016


Hi all
A South African in London here and I have decided to make the jump to
trying to help Swift develop.

I was an android and web developer and swift converted me to iOS
programming which has become something that I love. I have built several
apps on iOS and on macOS using it and thoroughly enjoyed it.

One think has made me fall a little out of love with swift 3 was
the removal of completion handler argument labels which has created:
1. Less maintainable code for teams
2. Less readable and thus more error prone code
3. Slower code to write as now I have to regularly scroll to the top of the
method to find out what the parameters should be .
4. Seems to be at odds with other parts of the api which favours labels.

I have found quite a lot of support from others via my stack overflow
question here:
http://stackoverflow.com/questions/39613272/xcode-8-function-types-cannot-have-argument-label-breaking-my-build

Here is my suggestion:
Currently the Swift 3 version does not allow arguments in the
completionhandler method, which is confusing and not very readable.

    func myMethod(_ completionhandler:(_ downloadedValue:String,_ isActive:
Bool, _ error:NSError)-> Void) {
        //<<After doing some async method such as downloading from an API >>

        completionhandler(myString, true, myError)

    }
    // INSTEAD: ideally the argument labels should be added optionally to
be called in the completion method such as below and using a Tuple-like
syntax to indicate that the method should have the labels

    func myMethod(_ completionhandler:( downloadedValue:String, isActive:
Bool,  error:NSError)-> Void) {

        //<<After doing some async method such as downloading from an API >>

        completionhandler(dowloadedValue:myString, isActive:true,
error:myError)

    }


Thanks for the help ( and any feedback on my idea above )

Thanks for the epic work you are doing !
-- 
Sent from my mobile
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161016/a1cae3ef/attachment.html>


More information about the swift-evolution mailing list