Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialViktor Opanasenko
1,712 Pointsin swift 3 var parameters are deprecated, so how then I can deal with this part - func countDownAndUp(var a: Int) { ?
While coding in playground I've noticed that in this part - func countDownAndUp(var a: Int) { - x-code shows "var parameters are deprecated and will be removed in Swift 3" but if I delete "var" the compiler shows an error. How can I deal with that? Thank you.
5 Answers
Viktor Opanasenko
1,712 PointsIt shows an error because "a" is not mutable when it is "let" and the challenge implies to increment the value of "a".
Christopher Ford
3,407 PointsI don't know too much about Swift I'm afraid - looking on Stack Overflow the suggestion (here: http://stackoverflow.com/questions/24077880/swift-make-method-parameter-mutable) seems to be that you should declare the var inside of your function like this:
func countDownAndUp(a:Int) -> Int {
var a = a
// etc
}
Viktor Opanasenko
1,712 Pointsstill don't know how to solve it(((((
Kristof Kocsis
15,455 PointsIf you are using Swift 3 for this video at 1:45 in the video your code should look something like this:
func countDownAndUp(a: Int) {
var b = a
var a = a
while b >= 0 {
b -= 1
a += 1
print("a: \(a)")
print("b: \(b)")
}
}
Rich Braymiller
7,119 Pointsstill doesn't solve the original issue....
Sam GGG
5,195 PointsHello!
I did what you said and it worked for me.
However, I tried to put a variable outside the func countDownAndUp: var a = 20. Then countDownAndUp (a: var a) and I got a few errors. Any idea why?
Thank you very much
Sam S
4,447 PointsChristopher's answer above is correct. In Swift 3, you should remove var from the parameter and introduce a local var variable. Apparently this change was introduced because people were confusing var parameters with inout parameters, which differ in scope. More info here: http://stackoverflow.com/questions/36164973/var-parameters-are-deprecated-and-will-be-removed-in-swift-3
Di Wu
Courses Plus Student 232 PointsIt's always a good practice not to modify parameters. This could reduce side effects :) I guess this is the reason var
params was deprecated and finally removed from Swift 3.
Christopher Ford
3,407 PointsChristopher Ford
3,407 PointsWhat happens if you replace 'var' with 'let'?