import UIKit
func Question() {
var questiontext : String
var answer : Bool
init(text: String , correctanswer: Bool ){ //error in this point : Initializers may only be declared within a type
questiontext = text
answer = correctanswer
}
}
我该如何解决这个问题?
答案 0 :(得分:2)
init
应该在class
/ struct
类型内,而不是func
class Question {
var questiontext : String
var answer : Bool
init(text: String , correctanswer: Bool ){
questiontext = text
answer = correctanswer
}
}