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 trial
Harley Sudewa
2,083 PointsIt keep saying to change var to let on the FactBook.swift file
It keep saying to change var to let on the FactBook.swift file
1 Answer
rh12
4,407 PointsI'm going to take a guess here, but I agree with Fuad - more information would be helpful.
My guess is that Xcode is suggesting (or warning) that you should change a var to let. This means that you declared something whose value has not been subsequently changed (or mutated).
Here is an example with a function that takes a String value and prints a greeting if said value is not nil. If however the value is nil, then another message is printed.
func sayHello(name:String?){
guard let name = name else {
var nameNotProvided = "Name not provided"
print(nameNotProvided)
return
}
print("Hello \(name)")
}
In the above code, the "nameNotProvided" variable is not being mutated by anything and thus should be declared as
let nameNotProvided = "Name not provided"
Finally, even though this is being presented as a warning from the compiler and won't stop you from building and executing your app, you probably should take care of it. Using the let keyword when its appropriate will make your code easier to reason about and reduce the chances that something that should remain constant does not change unexpectedly. It also makes your intentions clear to other developers in the future.
Hope this helps.
Fuad Adetoro
iOS Development Techdegree Student 11,599 PointsFuad Adetoro
iOS Development Techdegree Student 11,599 PointsNot enough description for someone to help you!