Manos Chorianopoulos

fix swiftApi models v2

...@@ -140,15 +140,23 @@ public class swiftApi { ...@@ -140,15 +140,23 @@ public class swiftApi {
140 self.category = dictionary["category"] as? String? ?? "" 140 self.category = dictionary["category"] as? String? ?? ""
141 self.barcode = dictionary["barcode"] as? String? ?? "" 141 self.barcode = dictionary["barcode"] as? String? ?? ""
142 self.status = dictionary["status"] as? Int? ?? nil 142 self.status = dictionary["status"] as? Int? ?? nil
143 - self.couponset_data = dictionary["couponset_data"] as? CouponSetItemModel? ?? nil
144 143
145 - let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""] 144 + if let couponSetData = dictionary["couponset_data"] as? [String: Any]? ?? ["":""] {
146 - let expirationString = expirationObject?["value"] as? String? ?? "" 145 +
146 + let tempCouponset = CouponSetItemModel(dictionary: couponSetData)
147 +
148 + self.couponset_data = tempCouponset
149 + } else {
150 + self.couponset_data = nil
151 + }
152 +
153 +
154 + let expirationString = dictionary["expiration"] as? String? ?? ""
147 155
148 // Example expirationString: Optional(2022-12-05 01:55) 156 // Example expirationString: Optional(2022-12-05 01:55)
149 157
150 let dateFormatter = DateFormatter() 158 let dateFormatter = DateFormatter()
151 - dateFormatter.dateFormat = "yyyy-MM-dd hh:mm" 159 + dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
152 if let date = dateFormatter.date(from: expirationString ?? "") { 160 if let date = dateFormatter.date(from: expirationString ?? "") {
153 dateFormatter.dateFormat = "dd/MM/yyyy" 161 dateFormatter.dateFormat = "dd/MM/yyyy"
154 let resultString = dateFormatter.string(from: date) 162 let resultString = dateFormatter.string(from: date)
...@@ -192,15 +200,15 @@ public class swiftApi { ...@@ -192,15 +200,15 @@ public class swiftApi {
192 let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>) 200 let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>)
193 if let sets = couponSetsData as? NSArray { 201 if let sets = couponSetsData as? NSArray {
194 for set in sets { 202 for set in sets {
195 - let s = set as! [String : Any] 203 + let s = set as! NSDictionary
196 if let cpns = couponsData as? NSArray { 204 if let cpns = couponsData as? NSArray {
197 for coupon in cpns { 205 for coupon in cpns {
198 - var c = coupon as! [String : Any] 206 + var c = coupon as! NSDictionary
199 // var temp = NSMutableDictionary(dictionary: s); 207 // var temp = NSMutableDictionary(dictionary: s);
200 if c["couponset_uuid"] as! String == s["uuid"] as! String { 208 if c["couponset_uuid"] as! String == s["uuid"] as! String {
201 let temp = NSMutableDictionary(dictionary: c); 209 let temp = NSMutableDictionary(dictionary: c);
202 210
203 - temp.setValue(s as [AnyHashable : Any],forKey: "couponset_data") 211 + temp.setValue(s as! [AnyHashable : Any],forKey: "couponset_data")
204 212
205 let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any]) 213 let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any])
206 couponsArray.append(tempCoupon) 214 couponsArray.append(tempCoupon)
......