【发布时间】:2018-07-07 23:21:27
【问题描述】:
我一直在搜索,但我发现的大多数答案都比我目前理解的要复杂。如果那里有教程,我会很感激一个链接,但这是我的问题:
我有多个具有相同机制和形式的函数,但调用不同的类。现在,我重复了很多相同的代码,我想有一种更短的方法可以做到这一点。这是一个例子:
func nextQuestion() {
switch analysisProgress {
case 7:
if questionProgress < ownershipQuestionList.list.count {
questionLabel.fadeTransition(0.4)
questionLabel.text = ownershipQuestionList.list[questionProgress].question
definitionText.text = ownershipQuestionList.list[questionProgress].definitions
} else {
self.performSegue(withIdentifier: "goToNarrativeVC", sender: nil)
}
case 9:
if questionProgress < discomfortQuestionList.list.count {
questionLabel.fadeTransition(0.4)
questionLabel.text = discomfortQuestionList.list[questionProgress].question
definitionText.text = discomfortQuestionList.list[questionProgress].definitions
} else {
self.performSegue(withIdentifier: "goToNarrativeVC", sender: nil)
}
case 10:
if questionProgress < resourceQuestionList.list.count {
questionLabel.fadeTransition(0.4)
questionLabel.text = resourceQuestionList.list[questionProgress].question
definitionText.text = resourceQuestionList.list[questionProgress].definitions
} else {
self.performSegue(withIdentifier: "goToNarrativeVC", sender: nil)
}
default:
()
}
处理这些情况的最佳方法是什么?
【问题讨论】:
-
在代码中显示三个不同列表变量的声明。
list属性从何而来,又是什么?