Unlike its predecessors C and Objective-C, Swift has the concept of types. By default, variables in cannot be set to , unless they are defined as an type. This is represented syntactically by appending a to the end of a type. For example, if you have an assignment, , you would change to . This will let you set to : . Optional Swift nil Optional ? var s: String = “” String String? s nil s = nil Unwrapping However, to use a variable with an type, it must be unwrapped. There are several ways of doing this: with an if-let statement, guard-let statement, or using a operator. The operator, is similar to the operator except it checks if the variable is before it and continuing with the operation. Optional ?. ?. . nil unwrapping . Since is not nil, the method is called on the unwrapped value of , while is nil and the method cannot be called, so the expression results in . str1 lowercased() str1 str2 nil There is another, slightly more risky way of unwrapping an and that is the operator instead of the , which unwraps an Optional without checking if it is . This tells the compiler that you “know” that the variable you are about forcibly unwrap is in fact not . For example, using the code above, would work just the same as . However, if the variable is , then a fatal error is thrown, which would be the case if was changed to . Optional ! ? nil nil str1!.lowercased() str1?.lowercased() nil str2?.lowercased() str2!.lowercased() Although is the only operator described here, you can also use before subscripting ( ) and calling. ?. ? [...] Implicitly Unwrapped Optionals A type can also be defined as implicitly-unwrapped, which is represented by appending an to the end of a type, for example . This means that a variable of type will be forcibly unwrapped without the need for the or operator. Since the variable can still be , this can cause fatal errors to occur if not used properly. Optional ! String! Optional ? ! nil If-let and guard-let Perhaps one of the most useful statements in Swift is an if-let and its sibling guard-let. As described above, an if-let allows you to unwrap an optional type, if the value is not , and use it in the body of the if-let statement. nil The if-let above takes , checks if it is , and if it isn’t assigns to the value of and executes the code inside the curly braces allowing access to , otherwise it will execute the statement. Notice, that once outside of the if-let block, is no longer available. str nil unwrappedStr str unwrappedStr else unwrappedStr Now, the guard-let does almost the opposite of an it-let: In the example above, the guard-let takes the variable of type, checks if it is , and if it isn’t the value of is assigned to , otherwise the code inside the block is executed. Note the return statement inside of the guard-let: you must either have a or (or something else that would cause the code to terminate such as a ), since is , it can’t be unwrapped and cannot be used. str Optional nil str unwrappedStr return break throw str nil unwrappedStr If you have any questions about types or anything Swift, or if you like what you’ve read and want to know more Swifty things, please leave a comment here or . Happy Swifting! Optional tweet or PM me on Twitter