Advertisement
darighteous1

swift-collections

Dec 3rd, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.65 KB | None | 0 0
  1. // Arrays
  2. var numbers:[Int] = Array(repeating: 0, count: 10)
  3. numbers[5] = 5
  4. print (numbers)
  5.  
  6. var names:[String] = Array()
  7.  
  8. // Sets
  9. var favoriteArtists: Set<String> = ["Weeknd", "Rihanna", "Seether"]
  10. favoriteArtists.insert("Alo")
  11. favoriteArtists.insert("Seether")
  12. print(favoriteArtists)
  13.  
  14. // Dictionary
  15. var places: [String:(lat: Double, lon: Double)] = ["Sofia":(42.7, 23.3), "Vienna":(48.12, 16.22), "San Francisco":(37.47, -122.25)]
  16.  
  17. print(places["Sofia"]?.lat)
  18. places["Barcelona"] = (47.23, 2.11) // insert
  19. places["Sofia"] = (42.65, 23.34) // modify
  20.  
  21. places.removeValue(forKey: "Sofia") // removes element
  22. places["Barcelona"] = nil
  23. print(places)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement