Skip to content

Commit a55c1c0

Browse files
(feat): SwiftLint added. (#210)
* Swift Linter added. * Fixed recommended changes by linter. * Podfile updated * update project to use pod * added SwiftLint to README credits
1 parent b1fd856 commit a55c1c0

File tree

100 files changed

+1128
-1168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1128
-1168
lines changed

DemoSwiftApp/AppDelegate.swift

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import UIKit
1818
import Optimizely
1919

20-
2120
@UIApplicationMain
2221
class AppDelegate: UIResponder, UIApplicationDelegate {
2322
let logLevel = OptimizelyLogLevel.debug
@@ -26,10 +25,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2625
let datafileName = "demoTestDatafile"
2726
let experimentKey = "background_experiment"
2827
let eventKey = "sample_conversion"
29-
28+
3029
let userId = String(Int.random(in: 0..<100000))
31-
let attributes: [String : Any?] = ["browser_type": "safari", "bool_attr": false]
32-
30+
let attributes: [String: Any?] = ["browser_type": "safari", "bool_attr": false]
31+
3332
var window: UIWindow?
3433
var optimizely: OptimizelyClient!
3534
var storyboard: UIStoryboard {
@@ -39,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3938
return UIStoryboard(name: "tvOSMain", bundle: nil)
4039
#endif
4140
}
42-
41+
4342
func applicationDidFinishLaunching(_ application: UIApplication) {
4443

4544
// initialize SDK in one of these two ways:
@@ -52,9 +51,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5251

5352
initializeOptimizelySDKWithCustomization()
5453
}
55-
54+
5655
// MARK: - Initialization Examples
57-
56+
5857
func initializeOptimizelySDKAsynchronous() {
5958
optimizely = OptimizelyClient(sdkKey: sdkKey, defaultLogLevel: logLevel)
6059

@@ -67,16 +66,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
6766
case .success:
6867
print("Optimizely SDK initialized successfully!")
6968
}
70-
69+
7170
self.startWithRootViewController()
7271
}
7372
}
74-
73+
7574
func initializeOptimizelySDKSynchronous() {
7675
guard let localDatafilePath = Bundle.main.path(forResource: datafileName, ofType: "json") else {
7776
fatalError("Local datafile cannot be found")
7877
}
79-
78+
8079
optimizely = OptimizelyClient(sdkKey: sdkKey, defaultLogLevel: logLevel)
8180

8281
addListeners()
@@ -89,24 +88,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
8988
} catch {
9089
print("Optimizely SDK initiliazation failed: \(error)")
9190
}
92-
91+
9392
startWithRootViewController()
9493
}
95-
94+
9695
func initializeOptimizelySDKWithCustomization() {
9796
// customization example (optional)
98-
97+
9998
let customLogger = CustomLogger()
10099
// 30 sec interval may be too frequent. This is for demo purpose.
101100
// This should be should be much larger (default = 10 mins).
102101
let customDownloadIntervalInSecs = 30
103-
102+
104103
optimizely = OptimizelyClient(sdkKey: sdkKey,
105104
logger: customLogger,
106105
periodicDownloadInterval: customDownloadIntervalInSecs,
107106
defaultLogLevel: logLevel)
108-
109-
107+
110108
addListeners()
111109

112110
// initialize SDK
@@ -123,16 +121,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
123121

124122
func addListeners() {
125123
// notification listeners
126-
124+
127125
_ = optimizely.notificationCenter.addDecisionNotificationListener(decisionListener: { (type, userId, attributes, decisionInfo) in
128126
print("Received decision notification: \(type) \(userId) \(String(describing: attributes)) \(decisionInfo)")
129127
})
130128

131129
_ = optimizely.notificationCenter.addTrackNotificationListener(trackListener: { (eventKey, userId, attributes, eventTags, event) in
132130
print("Received track notification: \(eventKey) \(userId) \(String(describing: attributes)) \(String(describing: eventTags)) \(event)")
133131
})
134-
135-
_ = optimizely.notificationCenter.addDatafileChangeNotificationListener(datafileListener: { (data) in
132+
133+
_ = optimizely.notificationCenter.addDatafileChangeNotificationListener(datafileListener: { (_) in
136134
DispatchQueue.main.async {
137135
#if os(iOS)
138136
if let controller = self.window?.rootViewController {
@@ -143,23 +141,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
143141
#else
144142
print("Datafile changed")
145143
#endif
146-
144+
147145
if let controller = self.window?.rootViewController as? VariationViewController {
148146
//controller.showCoupon = toggle == FeatureFlagToggle.on ? true : false;
149147
controller.showCoupon = self.optimizely.isFeatureEnabled(featureKey: "show_coupon",
150148
userId: self.userId)
151149
}
152150
}
153151
})
152+
154153
}
155154

156155
// MARK: - ViewControl
157-
156+
158157
func startWithRootViewController() {
159158
DispatchQueue.main.async {
160159
do {
161160
// For sample codes for other APIs, see "Samples/SamplesForAPI.swift"
162-
161+
163162
let variationKey = try self.optimizely.activate(experimentKey: self.experimentKey,
164163
userId: self.userId,
165164
attributes: self.attributes)
@@ -173,10 +172,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
173172
}
174173
}
175174
}
176-
175+
177176
func openVariationView(variationKey: String?) {
178177
let variationViewController = storyboard.instantiateViewController(withIdentifier: "VariationViewController") as! VariationViewController
179-
178+
180179
variationViewController.showCoupon = optimizely.isFeatureEnabled(featureKey: "show_coupon",
181180
userId: userId)
182181
variationViewController.optimizely = optimizely
@@ -190,29 +189,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
190189
func openFailureView() {
191190
window?.rootViewController = storyboard.instantiateViewController(withIdentifier: "FailureViewController")
192191
}
193-
192+
194193
// MARK: - AppDelegate
195-
194+
196195
func applicationWillResignActive(_ application: UIApplication) {
197196
}
198-
197+
199198
func applicationDidEnterBackground(_ application: UIApplication) {
200199
}
201-
200+
202201
func applicationWillEnterForeground(_ application: UIApplication) {
203202
}
204-
203+
205204
func applicationDidBecomeActive(_ application: UIApplication) {
206205
}
207-
206+
208207
func applicationWillTerminate(_ application: UIApplication) {
209208
}
210-
209+
211210
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
212-
211+
213212
// add background fetch task here
214-
213+
215214
completionHandler(.newData)
216215
}
217216
}
218-

DemoSwiftApp/Customization/CustomLogger.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ class CustomLogger: OPTLogger {
2121
}
2222
}
2323
}
24-

DemoSwiftApp/Samples/SamplesForAPI.swift

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,25 @@
1515
* limitations under the License. *
1616
***************************************************************************/
1717

18-
1918
import Foundation
2019
import Optimizely
2120

2221
class SamplesForAPI {
23-
22+
2423
static func run(optimizely: OptimizelyClient) {
25-
24+
2625
let attributes: [String: Any] = [
2726
"device": "iPhone",
2827
"lifetime": 24738388,
29-
"is_logged_in": true,
28+
"is_logged_in": true
3029
]
3130
let tags: [String: Any] = [
3231
"category": "shoes",
33-
"count": 2,
32+
"count": 2
3433
]
35-
34+
3635
// MARK: - activate
37-
36+
3837
do {
3938
let variationKey = try optimizely.activate(experimentKey: "my_experiment_key",
4039
userId: "user_123",
@@ -43,9 +42,9 @@ class SamplesForAPI {
4342
} catch {
4443
print(error)
4544
}
46-
45+
4746
// MARK: - getVariationKey
48-
47+
4948
do {
5049
let variationKey = try optimizely.getVariationKey(experimentKey: "my_experiment_key",
5150
userId: "user_123",
@@ -54,28 +53,28 @@ class SamplesForAPI {
5453
} catch {
5554
print(error)
5655
}
57-
56+
5857
// MARK: - getForcedVariation
59-
58+
6059
if let variationKey = optimizely.getForcedVariation(experimentKey: "my_experiment_key", userId: "user_123") {
6160
print("[getForcedVariation] \(variationKey)")
6261
}
63-
62+
6463
// MARK: - setForcedVariation
6564

6665
if optimizely.setForcedVariation(experimentKey: "my_experiment_key",
6766
userId: "user_123",
6867
variationKey: "some_variation_key") {
6968
print("[setForcedVariation]")
7069
}
71-
70+
7271
// MARK: - isFeatureEnabled
7372

7473
let enabled = optimizely.isFeatureEnabled(featureKey: "my_feature_key",
7574
userId: "user_123",
7675
attributes: attributes)
7776
print("[isFeatureEnabled] \(enabled)")
78-
77+
7978
// MARK: - getFeatureVariable
8079

8180
do {
@@ -87,12 +86,12 @@ class SamplesForAPI {
8786
} catch {
8887
print(error)
8988
}
90-
89+
9190
// MARK: - getEnabledFeatures
9291

9392
let enabledFeatures = optimizely.getEnabledFeatures(userId: "user_123", attributes: attributes)
9493
print("[getEnabledFeatures] \(enabledFeatures)")
95-
94+
9695
// MARK: - track
9796

9897
do {
@@ -102,6 +101,5 @@ class SamplesForAPI {
102101
print(error)
103102
}
104103
}
105-
106-
104+
107105
}

DemoSwiftApp/SharedResources/DemoSwifttvOS/Assets.xcassets/LaunchImage-2.launchimage/Contents.json

Lines changed: 0 additions & 49 deletions
This file was deleted.

DemoSwiftApp/VariationViewController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ import UIKit
1818
import Optimizely
1919

2020
class VariationViewController: UIViewController {
21-
21+
2222
var eventKey: String!
2323
var userId: String!
2424
var variationKey: String?
2525
var optimizely: OptimizelyClient?
2626
var showCoupon: Bool = false {
27-
didSet {
27+
didSet {
2828
DispatchQueue.main.async {
2929
self.couponView?.isHidden = !self.showCoupon
3030
}
3131
}
3232
}
3333

34-
@IBOutlet weak var couponView:UIView!
34+
@IBOutlet weak var couponView: UIView!
3535
@IBOutlet weak var variationLetterLabel: UILabel!
3636
@IBOutlet weak var variationSubheaderLabel: UILabel!
3737
@IBOutlet weak var variationBackgroundImage: UIImageView!
38-
38+
3939
@IBAction func closeCoupon(_ sender: UIButton) {
4040
showCoupon = false
4141
}
42-
42+
4343
@IBAction func unwindToVariationAction(unwindSegue: UIStoryboardSegue) {
4444
}
45-
45+
4646
@IBAction func attemptTrackAndShowSuccessOrFailure(_ sender: Any) {
4747
do {
4848
try self.optimizely?.track(eventKey: self.eventKey, userId: userId)
@@ -54,7 +54,7 @@ class VariationViewController: UIViewController {
5454

5555
override func viewDidLoad() {
5656
super.viewDidLoad()
57-
57+
5858
if let variationKey = self.variationKey {
5959
switch variationKey {
6060
case "variation_a":

0 commit comments

Comments
 (0)