Skip to content

Instantly share code, notes, and snippets.

@takasek
Created March 21, 2016 14:22
Show Gist options
  • Save takasek/fd0016b7d90492007627 to your computer and use it in GitHub Desktop.
Save takasek/fd0016b7d90492007627 to your computer and use it in GitHub Desktop.
TableViewCellとそのデータを複数パターン用意したい場合は、cellForRowAtIndexPathでswitch使うのが便利だと思う #CodePiece
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
switch (tableView.dequeueReusableCellWithIdentifier("cardCell", forIndexPath: indexPath), hand[indexPath.row]) {
case (let cell as? CardCell, let data as? Card):
cell.fillWith(data)
case (let cell as? HogeCell, let data as? Hoge):
cell.fillWith(data)
case (let cell as? FugaCell, let data as? Fuga):
cell.fillWith(data)
default:
fatalError("Could not create any Cell")
}
return cell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment