title: Implementing closure for specific method call in Swift
body: <p>I came across the following <code>UITableViewController</code> code and wanted to implement the associated <code>classes</code> and functions that go with them in order for me to learn a little bit more about Swift.</p>
  
  <p>I'm not sure what the implementation of <code>api.getRooms()</code> looks like. I think it may be a closure, but I'm not entirely sure?</p>
  
  <p>My question is what would <code>api.getRooms()</code> be returning considering there's <code>{}</code> usage? If anyone could explain to me what's going on that would be greatly appreciated.</p>
  
  <pre><code>api.getRooms(User.currentUser()!) { (roomsObj, error) in
      if let rooms = roomsObj as? Array&lt;Room&gt; {
          self.rooms = rooms
          self.tableView.reloadData()
          if (viaPullToRefresh) {
              self.refreshControl.endRefreshing()
          }
      }
  }
  </code></pre>
  
  <p><strong>PullViewController.swift</strong></p>
  
  <pre><code>class PullViewController: UITableViewController {
      var rooms = Array&lt;Room&gt;()
  
      init(coder aDecoder: NSCoder!) {
          super.init(coder: aDecoder)
  
          // Custom initialization
          assert(User.currentUser())
      }
  
      override func viewDidLoad() {
          self.refreshControl = UIRefreshControl()
          self.refreshControl.addTarget(self, action: Selector("refreshInvoked"), forControlEvents: UIControlEvents.ValueChanged)
          refresh()
      }
  
      override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -&gt; Int {
          return rooms.count
      }
  
      override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath:NSIndexPath!) -&gt; UITableViewCell! {
          var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell
          if !cell {
              cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier:"Cell")
          }
  
          let room = rooms[indexPath.row]
          cell!.textLabel.textColor = UIColor.blackColor()
          cell!.textLabel.text = "\(room.name)(\(room.messageCount))"
          return cell
      }
  
      func refreshInvoked() {
          refresh(viaPullToRefresh: true)
      }
  
      func refresh(viaPullToRefresh: Bool = false) {
          let api = API()
          api.getRooms(User.currentUser()!) { (roomsObj, error) in
              if let rooms = roomsObj as? Array&lt;Room&gt; {
                  self.rooms = rooms
                  self.tableView.reloadData()
                  if (viaPullToRefresh) {
                      self.refreshControl.endRefreshing()
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>User.swift</strong></p>
  
  <pre><code>class User {
  
      init() {
      }
  
      class func currentUser() -&gt; Bool {
          return true
      }
  }
  </code></pre>
  
  <p><strong>Room.swift</strong></p>
  
  <pre><code>class Room {
  
      var name: String
      var messageCount: Int
  
      init() {
      }
  }
  </code></pre>
  
  <p><strong>API.swift</strong> <em>(not sure whether this is implemented correctly).</em></p>
  
  <pre><code>class API {
  
      init() {
      }
  
      func getRooms(user: User) -&gt; (Array&lt;Room&gt;, String) { // ??
          // ??
      }
  }
  </code></pre>