Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2022-04-28 18:42:03 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c448a8916648a6f311953806d7aa1fe77d2b840d
c448a891
1 parent
f67b91eb
constructBarcode at CouponBarcodeView
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
1 deletions
WarplySDKFrameworkIOS/Media.xcassets/.DS_Store
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS/CouponBarcodeView.swift
WarplySDKFrameworkIOS/Media.xcassets/.DS_Store
View file @
c448a89
No preview for this file type
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
View file @
c448a89
No preview for this file type
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS/CouponBarcodeView.swift
View file @
c448a89
...
...
@@ -14,6 +14,34 @@ import UIKit
// import AVFoundation
extension
String
{
var
length
:
Int
{
return
count
}
subscript
(
i
:
Int
)
->
String
{
return
self
[
i
..<
i
+
1
]
}
func
substring
(
fromIndex
:
Int
)
->
String
{
return
self
[
min
(
fromIndex
,
length
)
..<
length
]
}
func
substring
(
toIndex
:
Int
)
->
String
{
return
self
[
0
..<
max
(
0
,
toIndex
)]
}
subscript
(
r
:
Range
<
Int
>
)
->
String
{
let
range
=
Range
(
uncheckedBounds
:
(
lower
:
max
(
0
,
min
(
length
,
r
.
lowerBound
)),
upper
:
min
(
length
,
max
(
0
,
r
.
upperBound
))))
let
start
=
index
(
startIndex
,
offsetBy
:
range
.
lowerBound
)
let
end
=
index
(
start
,
offsetBy
:
range
.
upperBound
-
range
.
lowerBound
)
return
String
(
self
[
start
..<
end
])
}
}
extension
CouponBarcodeView
{
struct
headerView
:
View
{
var
goBack
:
()
->
()
...
...
@@ -94,6 +122,41 @@ extension CouponBarcodeView {
return
nil
}
func
constructBarcode
()
->
String
?
{
// EAN 13 barcode construction
let
couponData
=
coupon
[
"coupon_data"
]
as?
[
String
:
Any
]
??
[
""
:
""
]
let
couponString
=
couponData
[
"coupon"
]
as?
String
??
""
if
(
!
couponString
.
isEmpty
)
{
var
checkDigit
=
0
;
var
result
=
0
;
var
fixedCouponCode
=
couponString
;
if
(
fixedCouponCode
.
count
<
12
)
{
let
loops
=
12
-
fixedCouponCode
.
count
;
var
zerosStr
=
""
;
for
i
in
0
..<
loops
{
zerosStr
+=
"0"
}
fixedCouponCode
=
zerosStr
+
fixedCouponCode
;
}
var
multiplier
=
3
;
for
idx
in
(
0
...
(
fixedCouponCode
.
count
-
1
))
.
reversed
()
{
let
curChar
=
fixedCouponCode
[
idx
];
result
+=
(
Int
(
curChar
)
??
0
)
*
multiplier
;
multiplier
=
multiplier
==
3
?
1
:
3
;
}
checkDigit
=
10
-
(
result
%
10
);
let
barcodeStr
=
fixedCouponCode
+
String
(
checkDigit
);
return
barcodeStr
;
}
return
""
}
var
body
:
some
View
{
...
...
@@ -197,7 +260,7 @@ extension CouponBarcodeView {
// .aspectRatio(contentMode: .fit)
// .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1)
Text
(
co
uponData
[
"coupon"
]
as?
String
??
""
)
Text
(
co
nstructBarcode
()
??
""
)
.
fontWeight
(
.
regular
)
.
font
(
.
system
(
size
:
22
))
.
foregroundColor
(
Color
(
red
:
0.2549019607843137
,
green
:
0.3333333333333333
,
blue
:
0.39215686274509803
))
...
...
Please
register
or
login
to post a comment