Skip to content

Instantly share code, notes, and snippets.

@axelrivera
Created November 29, 2015 18:42
Show Gist options
  • Save axelrivera/551697f4fa1729b81443 to your computer and use it in GitHub Desktop.
Save axelrivera/551697f4fa1729b81443 to your computer and use it in GitHub Desktop.
Custom data structures to help with complex UITableViews
import UIKit
typealias TableInfo = [String: Any]
typealias TableSectionArray = [TableSection]
typealias TableRowArray = [TableRow]
enum TableRowType {
case Text
case Detail
case Subtitle
case View
case Custom
}
struct TableSection {
var groupIdentifier: String?
var identifier: String?
var title: String?
var footer: String?
var rows = TableRowArray()
var userInfo = TableInfo()
init(title: String?, rows: TableRowArray) {
self.title = title
self.rows = rows
}
}
struct TableRow {
var rowType: TableRowType = .Custom
var identifier: String?
var groupIdentifier: String?
var text: String?
var detail: String?
var view: UIView?
var userInfo = TableInfo()
var object: Any?
var height: CGFloat?
init(type: TableRowType) {
self.rowType = type
}
init(type: TableRowType, text: String?, detail: String?) {
self.rowType = type
self.text = text
self.detail = detail
}
init(text: String?) {
self.rowType = .Text
self.text = text
}
init(text: String?, detail: String?) {
self.rowType = .Detail
self.text = text
self.detail = detail
}
init(text: String?, view: UIView?) {
self.rowType = .View
self.text = text
self.view = view
}
init(object: Any?) {
self.rowType = .Custom
self.object = object
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment