Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Error Handling in Swift 2.0 Error Handling Modeling Errors

Jacob Swedenburg
Jacob Swedenburg
252 Points

Why are you unwrapping types that are not optionals?

Why are you checking to see if name and age values exist if they are not declared as optionals? This seems backwards to me. Shouldn't you unwrap the optional type, not the non-optionals?

Lukas G.
Lukas G.
4,842 Points

If you get data from a dictionary, it's always an optional, since it's possible that no value exists for the key you provided. In this case Nil is returned and only Optionals can store the value Nil.

let someDict = ["A": "a", "B": "b"]

let someValue = someDict["A"]
let otherValue = someDict["C"]

someValue = optional("A") otherValue = Nil

In the friend struct "name " and "age" are not allowed to be Nil, since they are not of type optional. There is no need to unwrap address (of type optionalString), since we don't care what it stores, because even Nil is ok.