【发布时间】:2020-03-13 03:44:36
【问题描述】:
我有这个数组,我想按顺序在文本标签中打印问题。有没有可以读取每个问题的id并按顺序排序的功能?
这是我的代码:
struct Question {
let question: String
let id: Int
let answers: [ Answer ]
}
struct Answer {
let id: String
let answer: String
let isSelected: Bool
}
struct allQuestions {
let Questions = [
Question(question: "The easiest way to learn is:", id: 1, answers: [
Answer(id: "V", answer: "By viewing, reading, and observing how the others carry out certain tasks", isSelected: false),
Answer(id: "A", answer: "By listening, discussing and doing according to verbal instructions" , isSelected: false),
Answer(id: "K", answer: "By dping and experimenting by myself", isSelected: false)
]),
【问题讨论】:
-
你试过了吗?
-
我是 swift 的初学者,我目前一直在尝试提取问题 ID 并打印问题
-
Questions.sort { $0.id < $1.id } -
结构名称应以大写字母开头。变量名应以小写字母开头