Create Simple Table (UITableView) in Swift Language iOS8

Here is simple tutorial to create table (UITableView) in Swift Language – iOS 8 – Xcode 6

Swift Table
Swift Table

Attach your UITableView IBOutlet to .swift file

    @IBOutlet var tblSwift : UITableView = nil

Delegate UITableViewDelegate and UITableViewDataSource to your Controller

class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource
{
...
}

Don’t forgot to add the delegate methods otherwise you got error

class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource
{
    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
        ...
    }

    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
        ...
    }

    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
        ...
    }
}

Register your cell

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tblSwift.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

        // Do any additional setup after loading the view, typically from a nib.
    }

Following is sample of complete code

import UIKit

class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource
{

    @IBOutlet var tblSwift : UITableView = nil

    var items: String[] = ["This", "is" , "swift" , "language" , ":)"]

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tblSwift.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
        return self.items.count;
    }

    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
        var cell:UITableViewCell = self.tblSwift.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

        cell.textLabel.text = self.items[indexPath.row]
        return cell
    }

    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
        println("You selected item "+items[indexPath.row]) //or
        println("You selected item \(items[indexPath.row])") //or
        println("You selected cell #\(indexPath.row)!")
    }
}

Helping, Learning, Coding 🙂