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
Egor Bedunkevich
605 PointsWhy are we using if let?
Why do we use if let statement?
1 Answer
Chris Stromberg
Courses Plus Student 13,389 PointsIf your program tries to use an Optional that is equal to Nil ( has no value), your program will crash.
"if let" allows us to check and see if such an optional has a value or if its equal to nil.
If the optional is nil, the code in the brackets following "if let" will not be executed.
If the optional is not nil, the code in the brackets following "if let" will be executed.