Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var bucketList = ["Climb Mt. Everest"]
- var newItems = [
- "Fly hot air balloon to Fiji",
- "Watch the Lord of the Rings trilogy in one day",
- "Go on a walkabout", "Scuba dive in the Great Blue Hole",
- "Find a triple rainbow"
- ]
- bucketList += newItems
- bucketList
- bucketList.remove(at: 2)
- print(bucketList.count)
- print(bucketList[0...2])
- bucketList[2] += " in Australia"
- bucketList[0] = "Climb Mt. Kilimanjaro"
- bucketList.insert("Toboggan across Alaska", at: 2)
- bucketList
- // 1)find index of «Fly hot air balloon to Fiji
- // 2)unwrap
- // 3)compute index +2
- // 4)find the string
- if let i = bucketList.index(where: { $0 == "Fly hot air balloon to Fiji" }) {
- var newIndex = i + 2
- if newIndex > bucketList.count {
- print("Index out of range")
- } else {
- var nextGoal = bucketList[newIndex]
- print("The goal #\(newIndex) is: \(nextGoal)")
- }
- } else {
- print("No such item in array")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement