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

iOS Swift Functions and Optionals Optionals Optional Chaining

Why no if Let unwrapper to use sendNotice() after chaining ToInt to findApt("101")?

Since the chained function ToInt() also returns an optional, why do we get rid of the if let unwrapper?

1 Answer

sendNotice() doesn't return any values. Therefor it doesn't require unwrapping while calling it.

when you use toInt, by using an if let statement, you are unwrapping the integer and making it non optional. Now that you have unwrapped it, the if statement calls sendNotice(). Because sendNotice() is inside the if statement, it only happens if the optional is not nil.

If it was nil, the if statement didn't run, it wouldn't call sendNotice()