Skip to content

Instantly share code, notes, and snippets.

@axelrivera
Created October 25, 2017 00:48
Show Gist options
  • Save axelrivera/d116f8308cb9a7fcd291cf041a5521a1 to your computer and use it in GitHub Desktop.
Save axelrivera/d116f8308cb9a7fcd291cf041a5521a1 to your computer and use it in GitHub Desktop.
import Foundation
typealias TableInfo = [String: Any]
typealias TableSectionArray = [TableSection]
typealias TableRowArray = [TableRow]
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
}
}
extension TableSection: CustomStringConvertible {
var description: String {
let dictionary = [
"title": "\(String(describing: title))",
"rows": "\(rows)"
]
return "\(dictionary)"
}
}
struct TableRow {
enum Style {
case text
case detail
case subtitle
case custom
}
var style: Style = .custom
var identifier: String?
var groupIdentifier: String?
var text: String?
var detail: String?
var userInfo = TableInfo()
var object: Any?
var height: CGFloat?
init(style: Style, text: String?, detail: String?) {
self.style = style
self.text = text
self.detail = detail
}
init(text: String?, detail: String? = nil) {
if let _ = detail {
style = .detail
} else {
style = .text
}
self.text = text
self.detail = detail
}
init(object: Any?) {
self.style = .custom
self.object = object
}
}
extension TableRow: CustomStringConvertible {
var description: String {
let dictionary = [
"style": "\(style)",
"text": "\(String(describing: text))",
"detail": "\(String(describing: detail))"
]
return "\(dictionary)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment