Vasilis

coupons view data preparation

......@@ -3,22 +3,4 @@
uuid = "91478161-56E8-4654-93F2-7756A39480EE"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "28AEA58D-19E0-4D42-BABE-9F1C341D6182"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WarplySDKFrameworkIOS/CouponsView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "100"
endingLineNumber = "100"
landmarkName = "previews"
landmarkType = "24">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
......
......@@ -9,36 +9,53 @@
import SwiftUI
class DataModel {
var data: Array<NSDictionary>?
var data: Array<NSDictionary> = []
init() { //initializer method
let instanceOfMyApi = MyApi()
let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil)
let coupons = instanceOfMyApi.getCoupons() as AnyObject?
let coupons = instanceOfMyApi.getCoupons() as AnyObject?
if let myDictionary = coupons as? [String : AnyObject] {
self.data = (myDictionary["result"] as! Array<NSDictionary>)
if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] {
let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>)
if let myCouponsDictionary = coupons as? [String : AnyObject] {
let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>)
if let sets = couponSetsData as? NSArray {
for set in sets {
let s = set as! NSDictionary
if let cpns = couponsData as? NSArray {
for coupon in cpns {
var c = coupon as! NSDictionary
// var temp = NSMutableDictionary(dictionary: s);
if c["couponset_uuid"] as! String == s["uuid"] as! String {
var temp = NSMutableDictionary(dictionary: s);
temp.addEntries(from: c as! [AnyHashable : Any])
self.data.append(temp as NSDictionary)
}
}
}
}
}
}
}
}
var getData: Array<NSDictionary> {
get { // getter
return data ?? []
return data
}
}
}
@available(iOS 13.0.0, *)
struct CouponsView: View {
var data:Array<NSDictionary> = DataModel().getData
var uiscreen = UIScreen.main.bounds
// @State private var bottomRect: CGRect = .zero
var body: some View {
VStack {
extension CouponsView {
struct headerView: View {
var uiscreen = UIScreen.main.bounds
var body: some View {
ZStack {
Image("ic_back", bundle: Bundle(for: MyEmptyClass.self))
.resizable()
......@@ -49,41 +66,55 @@ struct CouponsView: View {
.offset( y: self.uiscreen.height * 0.07)
.frame(width: self.uiscreen.width)
}
}
}
struct couponView: View {
@Binding var result: NSDictionary
var uiscreen = UIScreen.main.bounds
var body: some View {
ZStack {
URLImage(url: URL(string: result["img_preview"] as! String? ?? ""))
// .resizable()
.frame(width: self.uiscreen.height * 0.04, height: self.uiscreen.height * 0.04)
.cornerRadius(CGFloat(self.uiscreen.height * 0.02))
// .offset(x: -self.uiscreen.width / 2 + self.uiscreen.width * 0.14, y: -self.uiscreen.height * 0.07)
}
// .background(
// Image("coupons_container", bundle: Bundle(for: MyEmptyClass.self))
// .resizable()
//// .edgesIgnoringSafeArea(.all)
// .frame(width: UIScreen.main.bounds.width * 0.8, height: UIScreen.main.bounds.height * 0.17)
// )
}
}
}
@available(iOS 13.0.0, *)
struct CouponsView: View {
var data:Array<NSDictionary> = DataModel().getData
var uiscreen = UIScreen.main.bounds
var body: some View {
VStack {
headerView()
ScrollView {
VStack {
// let dataArray:[NSDictionary] = (data as! NSArray).compactMap({ $0 as? NSDictionary })
// if (data?.count())! > 0 {
// data?.forEach { (language) in
// ForEach(data, id: \.self) { result in
//
//
//
// ZStack {
// Image("logo", bundle: Bundle(for: MyEmptyClass.self))
// .resizable()
// .frame(width: self.uiscreen.height * 0.04, height: self.uiscreen.height * 0.04, alignment: .topLeading)
// .cornerRadius(CGFloat(self.uiscreen.height * 0.02))
// .offset(x: -self.uiscreen.width / 2 + self.uiscreen.width * 0.14, y: -self.uiscreen.height * 0.07)
//
// }.background(
// Image("coupons_container", bundle: Bundle(identifier:"framework.warp.ly.warplySDKFrameworkIOS"))
// .resizable()
// .edgesIgnoringSafeArea(.all)
// .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
// )
//
if (data.count) > 0 {
ForEach(data, id: \.self) { result in
couponView(result: result)
}
}
//
}
.frame(width:self.uiscreen.width, height:self.uiscreen.height )
}
}
}
}
#endif
......