import UIKit
var list = [(categoryText: "Numbers", imageText: "Ten", audioText: "Ten"), (categoryText: "Numbers", imageText: "Eight", audioText: "Eight"), (categoryText: "Numbers", imageText: "Five", audioText: "Five"), (categoryText: "Colors", imageText: "Yellow", audioText: "Yellow"), (categoryText: "Colors", imageText: "Blue", audioText: "Blue"), (categoryText: "Colors", imageText: "Red", audioText: "Red") ]
let selectedCategory = "Numbers"
var selectedCatagoryArray = [Any]()
for index in list {
if index.categoryText == selectedCategory {
selectedCatagoryArray.append(index)
}
}
print(selectedCatagoryArray.description)
если вы делаете лучшую структуру кодирования, я бы предложил
struct Question {
var categoryText : String?
var imageText : String?
var audioText : String?
}
var list = [Question(categoryText: "Numbers", imageText: "Ten", audioText: "Ten"), Question(categoryText: "Numbers", imageText: "Eight", audioText: "Eight"), Question(categoryText: "Numbers", imageText: "Five", audioText: "Five"), Question(categoryText: "Colors", imageText: "Yellow", audioText: "Yellow"), Question(categoryText: "Colors", imageText: "Blue", audioText: "Blue"), Question(categoryText: "Colors", imageText: "Red", audioText: "Red") ]
let selectedCategory = "Numbers"
var selectedCatagoryArray = [Question]()
for question in list {
if question.categoryText == selectedCategory {
selectedCatagoryArray.append(question)
}
}
for element in selectedCatagoryArray {
print("Question : \(element.categoryText) + with image Text : \(element.imageText) + with audioText : \(element.audioText)" )
}