Swift 3 Dictionaries
These are formatted so you can copy the code straight into your Swift Playground files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
//create the Swift 3 Dictionary with nothing, and set the types // (String will be Key, and any object will be the value var someDict = [String : AnyObject]() //could use Any or AnyObject here // add a key and value someDict["Ex wives"] = 5 print (someDict) // add another key and value someDict["Current wives"] = 1 print (someDict) //remove Current wives. Oh well. someDict.removeValue(forKey: "Current wives") print (someDict) //changes ex wives to 6 someDict["Ex wives"] = 6 print (someDict) // remove all someDict.removeAll() |
If you’re looking for places to learn after these Swift Playground examples, check out CartoonSmart.com or SpriteKitLessons.com