Manos Chorianopoulos

fix swiftApi models v2

......@@ -140,15 +140,23 @@ public class swiftApi {
self.category = dictionary["category"] as? String? ?? ""
self.barcode = dictionary["barcode"] as? String? ?? ""
self.status = dictionary["status"] as? Int? ?? nil
self.couponset_data = dictionary["couponset_data"] as? CouponSetItemModel? ?? nil
let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""]
let expirationString = expirationObject?["value"] as? String? ?? ""
if let couponSetData = dictionary["couponset_data"] as? [String: Any]? ?? ["":""] {
let tempCouponset = CouponSetItemModel(dictionary: couponSetData)
self.couponset_data = tempCouponset
} else {
self.couponset_data = nil
}
let expirationString = dictionary["expiration"] as? String? ?? ""
// Example expirationString: Optional(2022-12-05 01:55)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm"
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
if let date = dateFormatter.date(from: expirationString ?? "") {
dateFormatter.dateFormat = "dd/MM/yyyy"
let resultString = dateFormatter.string(from: date)
......@@ -192,15 +200,15 @@ public class swiftApi {
let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>)
if let sets = couponSetsData as? NSArray {
for set in sets {
let s = set as! [String : Any]
let s = set as! NSDictionary
if let cpns = couponsData as? NSArray {
for coupon in cpns {
var c = coupon as! [String : Any]
var c = coupon as! NSDictionary
// var temp = NSMutableDictionary(dictionary: s);
if c["couponset_uuid"] as! String == s["uuid"] as! String {
let temp = NSMutableDictionary(dictionary: c);
temp.setValue(s as [AnyHashable : Any],forKey: "couponset_data")
temp.setValue(s as! [AnyHashable : Any],forKey: "couponset_data")
let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any])
couponsArray.append(tempCoupon)
......