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 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.