Dimitris Togias

add category title parsing & sorting of data

......@@ -11,11 +11,33 @@ public class CampaignCategory: Codable {
// attributes
public var name: String?
public var index: Int
public var items: Array<swiftApi.CampaignItemModel>
// initialization
public init(_ name: String) {
self.name = name
self.index = 100
self.items = [swiftApi.CampaignItemModel]()
}
public init(_ name: String, index: Int) {
self.name = name
self.index = index
self.items = [swiftApi.CampaignItemModel]()
}
}
enum CampaignCategoryFactory {
static func create(withTitle title: String) -> CampaignCategory {
var index = 100
let indexChr:Character = title[title.index(title.startIndex, offsetBy: 1)]
if indexChr.isNumber {
index = indexChr.wholeNumberValue!
}
return CampaignCategory(title, index: index)
}
}
......
......@@ -97,6 +97,7 @@ import SwiftEventBus
}
newData.append(category)
newData = newData.sorted(by: { $0.index > $1.index })
// reload
categories = newData
......