Skip to content

Instantly share code, notes, and snippets.

@externvoid
Created December 21, 2015 07:53
Show Gist options
  • Select an option

  • Save externvoid/e1c7121439b63b3fa20c to your computer and use it in GitHub Desktop.

Select an option

Save externvoid/e1c7121439b63b3fa20c to your computer and use it in GitHub Desktop.
nilが返るかもしれないメソッドの取り扱い
// nilが返るかもしれないメソッドの取り扱い
//let obj6 = NSUserDefaults.standardUserDefaults().objectForKey("user data")
var obj6: AnyObject? = nil
print(obj6)
var obj5 = obj6 as? [String: Int] ?? [String: Int]()
//var obj5: [String: Int] = obj! as [String: Int] ?? [String: Int]()
obj5["hp"] = 3
print(obj5) // ["hp": 3]
print(obj5.dynamicType) // Dictionary<String, Int>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment