Agung
Agung

Reputation: 13813

Using didSet property observer without stating 'oldValue'

i am a beginner in iOS development, i try to understand some code from someone for learning.

I am trying to populate the table view using JSON data from the API. when making the Table View Controller,i need to reload data since downloading data from API is multitasking

to reload the data and to display it to UI, he writes code like this

class VenuesTableViewController : UITableViewController {

var venues : [Venue] = [] {

    didSet {
        self.tableView.reloadData()
    }
}

he uses property observer 'didSet' to reload the table view.

but from what i learn from other tutorial, didSet usually uses 'oldValue' and we have to re assign some value to that class property before it works . (i.e var venues in my case)

so how come we can write didSet property obserserver without 'oldValue' and without reassign value to that property ?

Thanks in advance :)

Upvotes: 0

Views: 1036

Answers (1)

Rajesh Dalsaniya
Rajesh Dalsaniya

Reputation: 2127

didSet called every time after new value assigned to the variable venues. It is not compulsory to use oldValue within didSet. In short oldValue provide you scope of comparison with new value assigned or if you want to use it with any other task.

Upvotes: 1

Related Questions