View Controller Extensions

// DataSource 
func numberOfSectionsInTableView(tableview: UITableView) -> Int { return 1 // This will reflect the sections you need
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Data.dataStore.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let row = indexPath.row cell.textLabel?.text = Data.dataStore[row] return cell
}
// Delegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let row = indexPath.row print(Data.dataStore[row])
}

Welcome to the Extension Zone

extension ViewController: UITableViewDataSource { func numberOfSectionsInTableView(tableview: UITableView) -> Int { 
return 1 // This will reflect the sections you need
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Data.dataStore.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let row = indexPath.row cell.textLabel?.text = Data.dataStore[row] return cell
}
}
extension ViewController: UITableViewDelegate { func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
let row = indexPath.row print(Data.dataStore[row])
}
}

--

--

--

iOS engineer @ Spotify

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alex Persian

Alex Persian

iOS engineer @ Spotify

More from Medium

How to create a new Xcode project without Storyboard ?

Protecting ImageView content on iOS

Copy-on-Write in Swift Collections

Codable and key/property name not matching issue in Swift