class RoomsViewController: UITableViewController {
var rooms = Array<Room>()
override func viewDidLoad() {
super.viewDidLoad()
assert(User.currentUser())
let api = API()
api.getRooms(User.currentUser()!) { (roomsObj, error) in
if let rooms = roomsObj as? Array<Room> {
self.rooms = rooms
self.tableView.reloadData()
}
}
}
override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return rooms.count
}
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath:NSIndexPath!) -> UITableViewCell! {
var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("RoomCell") as? UITableViewCell
if !cell {
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier:"RoomCell")
}
let room = rooms[indexPath.row]
cell!.textLabel.textColor = UIColor.blackColor()
cell!.textLabel.text = "\(room.name)(\(room.messageCount))"
return cell
}
}