Swift 初始化后如何更改实例变量?

Swift 初始化后如何更改实例变量?,swift,initialization,Swift,Initialization,我是Swift的新手,正在尝试学习初始化器的概念。我在下面创建了SurveyQuestion(即cheeseQuestion)的一个实例 但是,在创建之后,我想将“var text:String”更改为“您喜欢哪种奶酪”?有人能告诉我怎么做吗 class SurveyQuestion{ var text: String var response: String? init(text: String){ self.text = text; }

我是Swift的新手,正在尝试学习初始化器的概念。我在下面创建了SurveyQuestion(即cheeseQuestion)的一个实例

但是,在创建之后,我想将“var text:String”更改为“您喜欢哪种奶酪”?有人能告诉我怎么做吗

class SurveyQuestion{
    var text: String
    var response: String?
    init(text: String){
        self.text = text;
    }
    func ask(){
        print(text)
    }
}

let cheeseQuestion = SurveyQuestion(text: "do you like cheese?")
cheeseQuestion.ask()
cheeseQuestion.response = "yes, i do like cheese"
没什么特别的

cheeseQuestion.text = "What kind of cheese do you like?"