Sign up for FlowVella
Sign up with FacebookAlready have an account? Sign in now
By registering you are agreeing to our
Terms of Service
Loading Flow
Unwrapping
Optional variables must be unwrapped using ! to access their value
Swift: Trying hard to help you avoid doing something dumb and getting NPEs
// Optional integer,
// allowed to be nil
var myOptionalVar : Int? = nil
myOptionalVar = 100
println (myOptionalVar! + 1)
Required Values
Variables in Swift are required to
have values (usually, see below)
Optional Variables
Optional variables are explicitly declared that they may have the value of nil
Use ! to Unwrap Optional Variables
Note the use of the exclamation point (!) at the end of the variable name in the last line