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
๋ฐ์ํ
'๐ Language > Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ๋์ ๋๋ฆฌ ๋ฐธ๋ฅ๊ฐ์ผ๋ก ํค๊ฐ ์์๋๋ก ์ ๋ ฌํ๊ธฐ(Sort Dictionary keys by values) (0) | 2020.08.25 |
---|---|
[Swift] Set์งํฉ์ index์์น ์์๋ด๊ธฐ (0) | 2020.05.13 |
Swift indices,compactMap,contentsOf (0) | 2020.04.04 |
[Swift] ๋ฌธ์์ด ๋ด๊ฐ ์ํ๋๋งํผ ์๋ฅด๊ธฐ (0) | 2020.01.19 |
Swift ์ด๋ฉ์ผ ํ์ ๊ฒ์ฌํ๊ธฐ(Email Validation) (0) | 2020.01.11 |
๋๊ธ