如何在字符串中查找子字符串,然后使用函数在子字符串之后打印所有内容

时间:2019-06-24 15:54:57

标签: swift string substring

在尝试实现我的代码时,我一直遇到很多问题。我是Swift的新手,语法令人沮丧。

我无法遍历字符串。我必须使用方法/库函数。

func findNextItem(from: String, in:[String]) -> String?{


return  nil
}

//FUNCTION MUST WORK WITH THE BELOW CODE
let bucketList = ["Travel to Antarctica", "Climb Mount Everest", "Run a 
marathon", "Write a book", "Build an iOS app"]
let item1 = findNextItem(from: "Write a book", in: bucketList)
let item2 = findNextItem(from: "Build an iOS app", in: bucketList)
let item3 = findNextItem(from: "Run a marathon", in: [])

print(item1!) // "Build an iOS app"
print(item2!) // "Travel to Antarctica"
print(item3)  // nil

0 个答案:

没有答案