Owen S
Owen S

Reputation: 55

Swift: Different versions of XCode giving different errors

I have just started learning the Swift programming language and was playing around with it in a playground with XCode Version 6.4. I just recently downloaded XCode Version 7.1 Beta because I was taking an online course on Swift and the course required I download XCode 7. When I opened the playground I was working on in XCode 6.4 with XCode 7.1 there were some errors that don't show up in Version 6.4. I guess this makes sense but I was wondering if you could look at the spots this happened and explain why it did.

Spot 1:

func walk(stepSize: Int, doIStep: Bool) -> Int {
    var x = 0
    if doIStep {
        x += stepSize
    }
    return x
}
func doStep() -> Bool {
    return true
}
walk(20, doStep())

(Error Missing argument label 'DoIStep:' in call on this line)

Spot 2:

func findSum(number1: Int, number2: Int) -> Int {
    var sum = 0
    func addNumbers() {
        sum = number1 + number2
    }
    addNumbers()
    return sum
}
findSum(20, 39)

(Error Missing argument label 'number2:' in call on this line)

Sorry, I know this is a long question, but I appreciate any answers! Thank you!

Upvotes: 0

Views: 53

Answers (1)

Eluss
Eluss

Reputation: 522

Using those functions should look like this:

walk(20, doIStep: doStep())
findSum(20, number2: 39)

in order to skip the second parameter name while calling function you have to declare it like this:

func findSum(number1: Int, _ number2: Int) -> Int

XCode 7 supports Swift 2 by default, but I think its not the case here. I think XCode 6.4 should show errors as well, don't know why it doesn't.

Upvotes: 1

Related Questions