This repository was archived by the owner on Jun 4, 2026. It is now read-only.
forked from venmo/Static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSection.swift
More file actions
90 lines (65 loc) · 2.28 KB
/
Copy pathSection.swift
File metadata and controls
90 lines (65 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import UIKit
/// Representation of a table section.
public struct Section: Hashable, Equatable {
// MARK: - Types
/// Representation of a section header or footer.
public enum Extremity {
/// System defined style for the title of the header or footer.
case Title(String)
/// Custom view for the header or footer. The height will be the view's `bounds.height`.
case View(UIView)
public var title: String? {
switch self {
case .Title(let extremityTitle): return extremityTitle
default: return nil
}
}
public var view: UIView? {
switch self {
case .View(let extremityView): return extremityView
default: return nil
}
}
public var viewHeight: CGFloat? {
return view?.bounds.height
}
}
// MARK: - Properties
/// Unique identifier used to identify the section.
public let UUID: String
/// Title or view for the header of the section.
public var header: Extremity?
/// Array of rows for the section.
public var rows: [Row]
/// Title or view for the header of the section.
public var footer: Extremity?
/// Section index title
public var indexTitle: String?
public var hashValue: Int {
return UUID.hashValue
}
// MARK: - Initiailizers
public init(header: Extremity? = nil, rows: [Row] = [], footer: Extremity? = nil, indexTitle: String? = nil, UUID: String = NSUUID().UUIDString) {
self.UUID = UUID
self.header = header
self.rows = rows
self.footer = footer
self.indexTitle = indexTitle
}
}
extension Section.Extremity: StringLiteralConvertible {
public typealias UnicodeScalarLiteralType = StringLiteralType
public typealias ExtendedGraphemeClusterLiteralType = StringLiteralType
public init(unicodeScalarLiteral value: UnicodeScalarLiteralType) {
self = .Title(value)
}
public init(extendedGraphemeClusterLiteral value: ExtendedGraphemeClusterLiteralType) {
self = .Title(value)
}
public init(stringLiteral value: StringLiteralType) {
self = .Title(value)
}
}
public func ==(lhs: Section, rhs: Section) -> Bool {
return lhs.UUID == rhs.UUID
}