@@ -21,7 +21,7 @@ public protocol PresentableSectionMarker {
2121
2222public typealias PresentableSectionMarkers = [ PresentableSectionMarker ]
2323
24- public class PresentableSection : PresentableSectionMarker {
24+ public class PresentableSection : PresentableSectionMarker , Collection {
2525
2626 public enum Animation {
2727 case none
@@ -52,7 +52,18 @@ public class PresentableSection: PresentableSectionMarker {
5252 }
5353
5454 public var presenterAnimation : Animation = . none
55+
56+ @available ( * , deprecated, message: " Use section.append(Presentable) directly " )
5557 public var presentables : [ PresentableType ] {
58+ get {
59+ return _presentables
60+ }
61+ set {
62+ _presentables = newValue
63+ }
64+ }
65+
66+ var _presentables : [ PresentableType ] {
5667 get {
5768 return bindablePresenters. value ?? [ ]
5869 }
@@ -61,6 +72,64 @@ public class PresentableSection: PresentableSectionMarker {
6172 }
6273 }
6374
75+ // MARK: Access
76+
77+ public var startIndex : Int {
78+ get {
79+ return 0
80+ }
81+ }
82+
83+ public var endIndex : Int {
84+ get {
85+ return _presentables. isEmpty ? 0 : ( _presentables. count - 1 )
86+ }
87+ }
88+
89+ public func index( after i: Int ) -> Int {
90+ if i >= count {
91+ fatalError ( " Presentable array index is out of bounds " )
92+ }
93+ return i + 1
94+ }
95+
96+ public subscript( index: Int ) -> PresentableType {
97+ get {
98+ return _presentables [ index]
99+ }
100+ set ( newValue) {
101+ _presentables [ index] = newValue
102+ }
103+ }
104+
105+ public func index( where predicate: ( PresentableType ) throws -> Bool ) rethrows -> Int ? {
106+ return try _presentables. index ( where: predicate)
107+ }
108+
109+ public func append( _ presentable: PresentableType ) {
110+ _presentables. append ( presentable)
111+ }
112+
113+ public func removeAll( ) {
114+ _presentables. removeAll ( )
115+ }
116+
117+ public func insert( _ presentable: PresentableType , at index: Int ) {
118+ _presentables. insert ( presentable, at: index)
119+ }
120+
121+ @discardableResult public func remove( at index: Int ) -> PresentableType {
122+ return _presentables. remove ( at: index)
123+ }
124+
125+ public var count : Int {
126+ return _presentables. count
127+ }
128+
129+ public var isEmpty : Bool {
130+ return _presentables. isEmpty
131+ }
132+
64133 // MARK: Initialization
65134
66135 public init ( ) { }
0 commit comments