Beginning iOS 10 Part 1 Getting Started - Part 5: | Ray Wenderlich

Adding controls isn't enough. They often need to be updated to reflect any changes in your app which you'll do in this episode.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3760-beginning-ios-10-part-1-getting-started/lessons/5

In the challenge finished example the code uses Guard let - is this discussed somewhere in the tutorials as I don’t think it was introduced

stackoverview! :smiley:

@tmacka Thanks very much for your question, and my apologies for the delay in responding to you!

The guard statement is more of a Swift syntax concept, rather than being related to an iOS issue.

That being said, the “guard” keyword is used to execute a code block, such that it provides an exit clause FIRST, thus allowing the compiler to avoid processing code before realizing that all conditions fail. Thus, “guard” allows the compiler to first check to see if in fact the condition meets, and then processes the code block if and only if that initial condition is met, otherwise, the else clause that is associated with the guard keyword is executed, and the compiler escapes.

The benefit of using the “guard” keyword is that it provides for much cleaner code, and helps the compiler to be more efficient, thus only executing lines of code it knows has passed the initial preconditions.

If you’re still unsure, be sure to check out some of the Swift courses that we have available. :slight_smile:

I hope this helps!