Day 2 – Complex Data Types

[cc_swift width=”100%” height = “100%”] // arrays let myArray = [“One”, “Two”, “Three”] // sets // in sets, all items must be unique and they are stored randomly let colors = Set([“red”, “green”, “blue”]) // tuples // in tuples, items cannot be added or removed, cannot change type // can access with numbers or name var name = (first: “Taylor”, last: “Swift”) name.first name.1 // dictionaries let myDictionary = [“Key1”: 12, “Key2”: 23] // default value let favoriteIceCream = [“Charlotte”: “Chocolate”, “Ali”: “Pistachio”] favoriteIceCream[“Denise”, default: “Unknown”] // creating empty collections let emptyArray = [String]() let emptyDictionary = [String : Int]() let emptySet = Set() // enumerations enum Result { case success case failure } let result1 = Result.success // enum associated values enum Activity { case bored case running(destination: String) case talking(topic: String) case singing(volume: Int) } let talking = Activity.singing(volume: 89) // enum raw values enum Planet: Int { case mercury case venus case earth case mars } let myPlanet = Planet(rawValue: 2) [/cc_swift]

Leave a Reply

Your email address will not be published. Required fields are marked *