@@ -47,7 +47,7 @@ class TradeItOrdersTableViewManager: NSObject, UITableViewDelegate, UITableViewD
4747 self . orderSectionPresenters = [ ]
4848
4949 let openOrders = orders. filter { $0. belongsToOpenCategory ( ) }
50- if openOrders. count > 0 {
50+ if ! openOrders. isEmpty {
5151 let openOrdersPresenter = getOrdersPresenter ( orders: openOrders)
5252 self . orderSectionPresenters. append (
5353 OrderSectionPresenter (
@@ -60,7 +60,7 @@ class TradeItOrdersTableViewManager: NSObject, UITableViewDelegate, UITableViewD
6060 }
6161
6262 let partiallyFilledOrders = orders. filter { $0. belongsToPartiallyFilledCategory ( ) }
63- if partiallyFilledOrders. count > 0 {
63+ if ! partiallyFilledOrders. isEmpty {
6464 let partiallyFilledOrdersPresenter = getOrdersPresenter ( orders: partiallyFilledOrders)
6565 self . orderSectionPresenters. append (
6666 OrderSectionPresenter (
@@ -73,7 +73,7 @@ class TradeItOrdersTableViewManager: NSObject, UITableViewDelegate, UITableViewD
7373 }
7474
7575 let filledOrders = orders. filter { $0. belongsToFilledCategory ( ) }
76- if filledOrders. count > 0 {
76+ if ! filledOrders. isEmpty {
7777 let filledOrdersPresenter = getOrdersPresenter ( orders: filledOrders)
7878 self . orderSectionPresenters. append (
7979 OrderSectionPresenter (
@@ -85,7 +85,7 @@ class TradeItOrdersTableViewManager: NSObject, UITableViewDelegate, UITableViewD
8585 }
8686
8787 let otherOrders = orders. filter { $0. belongsToOtherCategory ( ) }
88- if otherOrders. count > 0 {
88+ if ! otherOrders. isEmpty {
8989 let otherOrdersPresenter = getOrdersPresenter ( orders: otherOrders)
9090 self . orderSectionPresenters. append (
9191 OrderSectionPresenter (
@@ -103,11 +103,11 @@ class TradeItOrdersTableViewManager: NSObject, UITableViewDelegate, UITableViewD
103103 // MARK: UITableViewDelegate
104104
105105 func tableView( _ tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
106- return self . orderSectionPresenters [ safe : section] ? . title
106+ return getOrderSectionPresenter ( forSection : section) ? . title
107107 }
108108
109109 func tableView( _ tableView: UITableView , viewForHeaderInSection section: Int ) -> UIView ? {
110- if isAccountInfoSection ( section) {
110+ if Section ( rawValue : section) == Section . accountInfo {
111111 guard let cell = tableView. dequeueReusableCell ( withIdentifier: " BRANDED_ACCOUNT_NAME_CELL_ID " ) as? TradeItPreviewBrandedAccountNameCell else {
112112 return UITableViewCell ( )
113113 }
@@ -117,24 +117,24 @@ class TradeItOrdersTableViewManager: NSObject, UITableViewDelegate, UITableViewD
117117 return cell
118118 }
119119
120- return self . orderSectionPresenters [ safe : section] ? . header ( forTableView: tableView)
120+ return getOrderSectionPresenter ( forSection : section) ? . header ( forTableView: tableView)
121121 }
122122
123123 // MARK: UITableViewDataSource
124124 func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
125- if isAccountInfoSection ( indexPath. section) {
125+ if Section ( rawValue : indexPath. section) == Section . accountInfo {
126126 return UITableViewCell ( )
127127 } else {
128- return self . orderSectionPresenters [ safe : indexPath. section] ? . cell ( forTableView: tableView, andRow: indexPath. row) ?? UITableViewCell ( )
128+ return getOrderSectionPresenter ( forSection : indexPath. section) ? . cell ( forTableView: tableView, andRow: indexPath. row) ?? UITableViewCell ( )
129129 }
130130 }
131131
132132 func tableView( _ tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
133- if isAccountInfoSection ( section) {
133+ if Section ( rawValue : section) == Section . accountInfo {
134134 return 0
135135 }
136136
137- guard let orderSectionPresenter = self . orderSectionPresenters [ safe : section] else { return 0 }
137+ guard let orderSectionPresenter = getOrderSectionPresenter ( forSection : section) else { return 0 }
138138 return orderSectionPresenter. numberOfRows ( )
139139 }
140140
@@ -147,15 +147,15 @@ class TradeItOrdersTableViewManager: NSObject, UITableViewDelegate, UITableViewD
147147 }
148148
149149 func tableView( _ tableView: UITableView , estimatedHeightForRowAt indexPath: IndexPath ) -> CGFloat {
150- guard let orderPresenter = self . orderSectionPresenters [ safe : indexPath. section] ? . ordersPresenter [ safe: indexPath. row]
150+ guard let orderPresenter = getOrderSectionPresenter ( forSection : indexPath. section) ? . ordersPresenter [ safe: indexPath. row]
151151 , !orderPresenter. isGroupOrderHeader else {
152152 return TradeItOrdersTableViewManager . GROUP_ORDER_HEADER_HEIGHT
153153 }
154154 return UITableViewAutomaticDimension
155155 }
156156
157157 func tableView( _ tableView: UITableView , heightForRowAt indexPath: IndexPath ) -> CGFloat {
158- guard let orderPresenter = self . orderSectionPresenters [ safe : indexPath. section] ? . ordersPresenter [ safe: indexPath. row]
158+ guard let orderPresenter = getOrderSectionPresenter ( forSection : indexPath. section) ? . ordersPresenter [ safe: indexPath. row]
159159 , !orderPresenter. isGroupOrderHeader else {
160160 return TradeItOrdersTableViewManager . GROUP_ORDER_HEADER_HEIGHT
161161 }
@@ -168,7 +168,7 @@ class TradeItOrdersTableViewManager: NSObject, UITableViewDelegate, UITableViewD
168168
169169 func tableView( _ tableView: UITableView , editActionsForRowAt indexPath: IndexPath ) -> [ UITableViewRowAction ] ? {
170170 let cancelAction = UITableViewRowAction ( style: . normal, title: " Cancel " ) { ( action, indexPath: IndexPath ) in
171- guard let orderPresenter = self . orderSectionPresenters [ safe : indexPath. section] ? . ordersPresenter [ safe: indexPath. row]
171+ guard let orderPresenter = self . getOrderSectionPresenter ( forSection : indexPath. section) ? . ordersPresenter [ safe: indexPath. row]
172172 , let ordernumber = orderPresenter. getOrderNumber ( ) else {
173173 return
174174 }
@@ -182,7 +182,7 @@ class TradeItOrdersTableViewManager: NSObject, UITableViewDelegate, UITableViewD
182182 }
183183
184184 func tableView( _ tableView: UITableView , canEditRowAt indexPath: IndexPath ) -> Bool {
185- guard let orderPresenter = self . orderSectionPresenters [ safe : indexPath. section] ? . ordersPresenter [ safe: indexPath. row] else {
185+ guard let orderPresenter = getOrderSectionPresenter ( forSection : indexPath. section) ? . ordersPresenter [ safe: indexPath. row] else {
186186 return false
187187 }
188188 return orderPresenter. isCancelable ( )
@@ -191,10 +191,16 @@ class TradeItOrdersTableViewManager: NSObject, UITableViewDelegate, UITableViewD
191191 func tableView( _ tableView: UITableView , commit editingStyle: UITableViewCellEditingStyle , forRowAt indexPath: IndexPath ) {
192192 // nothing to do but need to be defined to display the actions
193193 }
194-
194+
195195 // MARK: Private
196- private func isAccountInfoSection( _ section: Int ) -> Bool {
197- return section == 0
196+ fileprivate enum Section : Int {
197+ case accountInfo = 0 , firstOrderCategory
198+ }
199+
200+ private func getOrderSectionPresenter( forSection section: Int ) -> OrderSectionPresenter ? {
201+ let indexOfOrderCategory = section - Section. firstOrderCategory. rawValue
202+
203+ return orderSectionPresenters [ safe: indexOfOrderCategory]
198204 }
199205
200206 private func addRefreshControl( toTableView tableView: UITableView ) {
0 commit comments