Beginning Swift 3 - Part 12: Dictionaries | Ray Wenderlich

Learn about dictionaries in Swift 3.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4095-beginning-swift-3/lessons/12

Hi!

There is a typo in the instructions on line 20. It says 53 should be 54.

Bob

Thanks for the heads up!

I may be wrong but, isn’t the entire point of Swift’s if let statements to stop users from doing a != nil? You only want to force unwrap a variable when you know for sure it is not nil. I noticed you did the != nil syntax as well in the optionals video.

Hey Simon,

There are different ways to unwrap a variable. Just like the video, you only want to force unwrap a variable when you know the value is not nil. As you saw in the video he did an if statement to make sure the values did not contain nil values. If they were to contain nil values, the if statement wouldn’t run.

Ways to unwrap an optional.

  1. Use ! - NOT RECOMMENDED, IF NIL VALUE YOUR APP WILL CRASH

  2. Use an “If Let”

  3. Use a “Guard Statement” - Typically used in methods/functions

1 Like

Well put, andresaguero10!