Swift Programming: getter/setter in stored property

Ok. Reading through Apples documentation on Swift I found this:

If you assign a value to a property within its own didSet observer,
the new value that you assign will replace the one that was just set.

So all you have to do is this:

var rank: Int = 0 {
    didSet {
        // Say 1000 is not good for you and 999 is the maximum you want to be stored there
        if rank >= 1000  {
            rank = 999
        }
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)