Reputation: 10058
I'm new to Swift and is trying to learn the concept of initialiser. I have created an instance of SurveyQuestion (i.e. cheeseQuestion) below.
However, after creation, I want to change the 'var text: String' to "what kind of cheese do you like"? Could someone please kindly tell me how it could be done?
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"
Upvotes: 2
Views: 32
Reputation: 8883
cheeseQuestion.text = "What kind of cheese do you like?"
Nothing special.
Upvotes: 1