๐ Language/Swift
[Swift] keyword๋ฅผ ์ด์ฉํด์ ๊ฒ์ํ๋ ๋ฒ
Fomagran ๐ป
2019. 12. 5. 01:04
728x90
๋ฐ์ํ
์ฝ๋๋ฅผ ๋ถ์ฌ๋ฃ์ ์ ์๋ค๋ ๊ฑธ ์ฒ์ ์์๋ค.
let recipes = ["Put eggs in a frying pan", "Cut the beef", "Boil the beef"]
let keyword = "beef"
func search(recipes:[String],keyword:String) -> [String]{
var foundRecipes = [String]()
for recipe in recipes{
if recipe.contains(keyword) == true {
foundRecipes.append(recipe)
}
}
return foundRecipes
}
var a = search(recipes: recipes, keyword: "egg")
๋ด๊ฐ ์๊ฐํ ํต์ฌ์ contains์ append๋ฅผ ์๊ณ ์๋๋ ์๋๋ ๊ฐ๋ค!
728x90
๋ฐ์ํ