Skip to content

Instantly share code, notes, and snippets.

@hachinobu
Last active August 29, 2015 14:21
Show Gist options
  • Save hachinobu/1033e403e01ebd59b24f to your computer and use it in GitHub Desktop.
Save hachinobu/1033e403e01ebd59b24f to your computer and use it in GitHub Desktop.
Swift Optional
let a: String?
let b: String!
let c: String

a = nil //OK
b = nil //OK
c = nil //NG

println(a) //OK
println(b) //NG nilに対してアンラップしようとして落ちる

上記はどれも意味が別

記号が付いている場合はnil代入可能 !の方はアンラップ不要だがnilに対して操作しようとすると落ちる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment