import UIKit
var options = [String]()
var correctAns = Int()
var question : String
class quizController: UIViewController {
@IBOutlet weak var questionLabel: UILabel!
@IBOutlet weak var button1: UIButton!
@IBOutlet weak var button2: UIButton!
@IBOutlet weak var button3: UIButton!
@IBOutlet weak var button4: UIButton!
init() {
question = "What quiz are you taking?"
options = ["Medical", "Bollywood", "Math", "Trivia"]
correctAns = 0
}
struct shuffle {
var readyToAskQuestions : [quizController] {
var questions = Array(arrayLiteral: question)
questions.count = questionNum
questions.shuffleInPlace()
return questions
}
init() {
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}我在全局var问题中得到了一个错误:需要初始化的字符串行(全局'var‘声明需要初始化表达式或getter/setter说明符)。
但是,如果我确实尝试初始化它,则会在结构中得到几个错误:
我如何重构我的代码,以便在不遇到这些错误的情况下初始化全局变量。
发布于 2015-08-20 06:38:32
questions是String的数组。Swift数组没有一个名为shuffleInPlace的方法。quizController的readyToAskQuestions数组的类型。它期望quizController作为返回值,而不是返回字符串,这是错误的。看来你对斯威夫特很陌生。不能让你在这个答案中把所有这些事情都弄清楚。强烈推荐阅读苹果快速编程电子书。
https://stackoverflow.com/questions/32110066
复制相似问题