Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

1458279

Suspended
Original poster
https://www.hackingwithswift.com/swift3

I'm watching some Swift 3 videos and blogs and noticed this new underscore option.

Seems that if you use the underscore in front of a parameter, you don't need to have a named parameter.

Code:
func sendMessage(_ message: String, to recipient: String, shouting: Bool) {
    var message = "\(message), \(recipient):"
    if shouting {
        message = message.uppercaseString
    }
    print(message)
}

sendMessage("see you at the Bash", to: "Morgan", shouting: false)

@19:30


I don't have Swift 3 yet so I can't test everything.

Q. what happens if you put the underscore under each parameter?

Does this make it so you can have no parameter names on all of the parameters or is it just the 1st parameter?
 
Watching more of the video, I see @ 23:20, this:
func filterInts(_ numbers: [int], _ includeNumber: type) -> [Int] {...}

So wouldn't that mean that the underscore can be used on any parameter?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.