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 trialMatthew Chana
1,063 PointsWhy doesn't the 'culprit' constant in the if let conditional require a "==" (is equal to)?
So the corret code is: if let culprit = findApt("101") { println("Apt Found: (culprit)") }
but I intuitively thought it would be: if let culprit == findApt("101") { println("Apt Found: (culprit)") }
3 Answers
Stephen McMillan
iOS Development with Swift Techdegree Graduate 33,994 Points== isn't required because we are assigning 'let culprit' to the return value of the function findApt() . The IF statement is there to make sure we are not trying unwrap(!) an optional that is nil.
Matthew Chana
1,063 PointsCool and thanks, so, because of this, this can be considered different than a stand-alone if then conditional?
Ed Williams
2,969 PointsThey are both IF conditionals, but this one is different in the way that it is checking if the constant is assigned a value, whereas with '==' we are checking if the two variables on either side of the comparison operator are equal.
Jorge Escalante
Front End Web Development Techdegree Student 2,080 PointsAnd if the findApt function is equal to nil the if statament is taken as false ? I'm still confused :\