If I have a ScoreModel
for my app that I need to pass to the next UIViewController
. It may not exist and thus not passed to this new UIViewController
. If this is the case I would like to have it create a new instance of the Model. This won't work (endless loop) but it will give the idea of what i'm trying to create:
var scoreModel : ScoreModel! {
get {
if self.scoreModel == nil {
return ScoreModel()
} else {
return self.scoreModel
}
}
set {
self.scoreModel = newValue
}
}
How can I check if the current version of scoreModel == nil
without getting in a loop?
What if, instead of trying to mess around with custom getters/setters, you just made your scoreModel property optional (better convention anyway) and when you want to pass it to the next view controller you check if its nil. Something like this: