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 trialRoland O'Donnell
5,667 Pointschanging func input parameters to a var? I get a warning saying var parameters are deprecated & will b removed in swift3
//example
func countDownAndup(var a: Int) {
var b = a
while b >= 0 {
b -= 1
a += 1
print ("a: \(a)")
print ("b: \(b)")
}
}
1 Answer
Cindy Lea
Courses Plus Student 6,497 PointsYes, they are talking about this online & advise using shadowing. According to stackoverflow.com : http://stackoverflow.com/questions/36414183/swift-3-var-deprecated-error/36414199
In swift 3.0 variable parameters to functions will be removed. This is due to the designers of the language believe it can be ambiguous with inout variables. You can use shadowing to easily fix this like so:
func filterContentForSearchText(searchText: String, scope: NSInteger) {
var searchText = searchText
searchText = searchText.lowercaseString;
Here we assign a local variable searchText to be the value of the constant searchText parameter. Due to shadowing the local variable is what is referenced when searchText is used.