Showing
2 changed files
with
23 additions
and
0 deletions
... | @@ -11,11 +11,33 @@ public class CampaignCategory: Codable { | ... | @@ -11,11 +11,33 @@ public class CampaignCategory: Codable { |
11 | 11 | ||
12 | // attributes | 12 | // attributes |
13 | public var name: String? | 13 | public var name: String? |
14 | + public var index: Int | ||
14 | public var items: Array<swiftApi.CampaignItemModel> | 15 | public var items: Array<swiftApi.CampaignItemModel> |
15 | 16 | ||
16 | // initialization | 17 | // initialization |
17 | public init(_ name: String) { | 18 | public init(_ name: String) { |
18 | self.name = name | 19 | self.name = name |
20 | + self.index = 100 | ||
21 | + self.items = [swiftApi.CampaignItemModel]() | ||
22 | + } | ||
23 | + | ||
24 | + public init(_ name: String, index: Int) { | ||
25 | + self.name = name | ||
26 | + self.index = index | ||
19 | self.items = [swiftApi.CampaignItemModel]() | 27 | self.items = [swiftApi.CampaignItemModel]() |
20 | } | 28 | } |
21 | } | 29 | } |
30 | + | ||
31 | +enum CampaignCategoryFactory { | ||
32 | + static func create(withTitle title: String) -> CampaignCategory { | ||
33 | + | ||
34 | + var index = 100 | ||
35 | + let indexChr:Character = title[title.index(title.startIndex, offsetBy: 1)] | ||
36 | + if indexChr.isNumber { | ||
37 | + index = indexChr.wholeNumberValue! | ||
38 | + } | ||
39 | + | ||
40 | + return CampaignCategory(title, index: index) | ||
41 | + } | ||
42 | +} | ||
43 | + | ... | ... |
... | @@ -97,6 +97,7 @@ import SwiftEventBus | ... | @@ -97,6 +97,7 @@ import SwiftEventBus |
97 | } | 97 | } |
98 | 98 | ||
99 | newData.append(category) | 99 | newData.append(category) |
100 | + newData = newData.sorted(by: { $0.index > $1.index }) | ||
100 | 101 | ||
101 | // reload | 102 | // reload |
102 | categories = newData | 103 | categories = newData | ... | ... |
-
Please register or login to post a comment