Advertisement
KonstantyNil

Untitled

Aug 18th, 2017
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.93 KB | None | 0 0
  1. var bucketList = ["Climb Mt. Everest"]
  2. var newItems = [
  3.     "Fly hot air balloon to Fiji",
  4.     "Watch the Lord of the Rings trilogy in one day",
  5.     "Go on a walkabout", "Scuba dive in the Great Blue Hole",
  6.     "Find a triple rainbow"
  7. ]
  8. bucketList += newItems
  9. bucketList
  10. bucketList.remove(at: 2)
  11. print(bucketList.count)
  12. print(bucketList[0...2])
  13. bucketList[2] += " in Australia"
  14. bucketList[0] = "Climb Mt. Kilimanjaro"
  15. bucketList.insert("Toboggan across Alaska", at: 2)
  16. bucketList
  17.  
  18. //  1)find index of «Fly hot air balloon to Fiji
  19. //  2)unwrap
  20. //  3)compute index +2
  21. //  4)find the string
  22.  
  23. if let i = bucketList.index(where: { $0 == "Fly hot air balloon to Fiji" }) {
  24.     var newIndex = i + 2
  25.         if newIndex > bucketList.count {
  26.         print("Index out of range")
  27.     } else {
  28.     var nextGoal = bucketList[newIndex]
  29.     print("The goal #\(newIndex) is: \(nextGoal)")
  30. }
  31. } else {
  32.     print("No such item in array")
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement