Skip to content

Commit 6406f25

Browse files
committed
add sample codes
1 parent c31df22 commit 6406f25

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

DemoSwiftApp/DemoSwiftApp.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
6EDBCE0022710E87009DF724 /* CustomLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EDBCDF522710E87009DF724 /* CustomLogger.swift */; };
3333
6EDBCE0122710E87009DF724 /* CustomLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EDBCDF522710E87009DF724 /* CustomLogger.swift */; };
3434
6EF2CF1D21E4158A00A5D78D /* tvOSMain.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6EF2CF1B21E4158A00A5D78D /* tvOSMain.storyboard */; };
35+
6EFA31F5227BB60E006FA572 /* SamplesForAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EFA31F4227BB60E006FA572 /* SamplesForAPI.swift */; };
3536
89E1F14CFCF4A1AA5AC0C8CB /* Pods_DemoSwiftiOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B886F5E161647DB427A8FBC /* Pods_DemoSwiftiOS.framework */; };
3637
/* End PBXBuildFile section */
3738

@@ -173,6 +174,7 @@
173174
6E96819421EEA391009B7FEC /* ProximaNova-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ProximaNova-Regular.otf"; sourceTree = "<group>"; };
174175
6EDBCDF522710E87009DF724 /* CustomLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomLogger.swift; sourceTree = "<group>"; };
175176
6EF2CF1C21E4158A00A5D78D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/tvOSMain.storyboard; sourceTree = "<group>"; };
177+
6EFA31F4227BB60E006FA572 /* SamplesForAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SamplesForAPI.swift; sourceTree = "<group>"; };
176178
9C185BE70FBE51067CFD104E /* Pods-DemoSwiftiOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoSwiftiOS.release.xcconfig"; path = "../Pods/Target Support Files/Pods-DemoSwiftiOS/Pods-DemoSwiftiOS.release.xcconfig"; sourceTree = "<group>"; };
177179
B301A636D5072557B288E62C /* Pods-DemoSwifttvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoSwifttvOS.release.xcconfig"; path = "../Pods/Target Support Files/Pods-DemoSwifttvOS/Pods-DemoSwifttvOS.release.xcconfig"; sourceTree = "<group>"; };
178180
CCC404BE4046CDA1D3A9C26B /* Pods_DemoSwifttvOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DemoSwifttvOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -301,6 +303,7 @@
301303
EA299EE31E55313B00931399 /* FailureViewController.swift */,
302304
EA299EE41E55313B00931399 /* SplashScreenViewController.swift */,
303305
EA1E4AA51E5FD1C100BDDABD /* DemoSwiftApp-Bridging-Header.h */,
306+
6EFA31F4227BB60E006FA572 /* SamplesForAPI.swift */,
304307
6E96811A21EE9552009B7FEC /* Customization */,
305308
EA5246BF1DC7186800AF6685 /* DemoSwiftiOS */,
306309
EA299ED51E5530A400931399 /* DemoSwifttvOS */,
@@ -636,6 +639,7 @@
636639
25C6F3BC21C95D2100C2EBDD /* VariationViewController.swift in Sources */,
637640
6EDBCE0022710E87009DF724 /* CustomLogger.swift in Sources */,
638641
25C6F3B621C95D1700C2EBDD /* AppDelegate.swift in Sources */,
642+
6EFA31F5227BB60E006FA572 /* SamplesForAPI.swift in Sources */,
639643
25C6F3BB21C95D1E00C2EBDD /* SplashScreenViewController.swift in Sources */,
640644
);
641645
runOnlyForDeploymentPostprocessing = 0;

DemoSwiftApp/SamplesForAPI.swift

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//
2+
/****************************************************************************
3+
* Copyright 2019, Optimizely, Inc. and contributors *
4+
* *
5+
* Licensed under the Apache License, Version 2.0 (the "License"); *
6+
* you may not use this file except in compliance with the License. *
7+
* You may obtain a copy of the License at *
8+
* *
9+
* http://www.apache.org/licenses/LICENSE-2.0 *
10+
* *
11+
* Unless required by applicable law or agreed to in writing, software *
12+
* distributed under the License is distributed on an "AS IS" BASIS, *
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14+
* See the License for the specific language governing permissions and *
15+
* limitations under the License. *
16+
***************************************************************************/
17+
18+
19+
import Foundation
20+
21+
extension AppDelegate {
22+
23+
func samplesForAPI() {
24+
25+
let attributes = ["country": "us"]
26+
let eventTags = ["price": "100"]
27+
28+
if let variationKey = try? optimizely.activate(experimentKey: "experimentKey",
29+
userId: "userId",
30+
attributes: attributes) {
31+
print("[activate] \(variationKey)")
32+
}
33+
34+
if let variationKey = try? optimizely.getVariationKey(experimentKey: "experimentKey",
35+
userId: "userId",
36+
attributes: attributes) {
37+
print("[getVariationKey] \(variationKey)")
38+
}
39+
40+
if let variationKey = optimizely.getForcedVariation(experimentKey: "experimentKey", userId: "userId") {
41+
print("[getForcedVariation] \(variationKey)")
42+
}
43+
44+
if optimizely.setForcedVariation(experimentKey: "experimentKey",
45+
userId: "userId",
46+
variationKey: "variationKey") {
47+
print("[setForcedVariation]")
48+
}
49+
50+
do {
51+
let result = try optimizely.isFeatureEnabled(featureKey: "featureKey",
52+
userId: "userId",
53+
attributes: attributes)
54+
print("[isFeatureEnabled] \(result)")
55+
} catch {
56+
// error
57+
}
58+
59+
if let value = try? optimizely.getFeatureVariableBoolean(featureKey: "featureKey",
60+
variableKey: "kBoolean",
61+
userId: "userId",
62+
attributes: attributes) {
63+
print("[getFeatureVariableBoolean] \(value)")
64+
}
65+
66+
if let value = try? optimizely.getFeatureVariableDouble(featureKey: "featureKey",
67+
variableKey: "kDouble",
68+
userId: "userId",
69+
attributes: attributes) {
70+
print("[getFeatureVariableDouble] \(value)")
71+
}
72+
73+
if let value = try? optimizely.getFeatureVariableInteger(featureKey: "featureKey",
74+
variableKey: "kInteger",
75+
userId: "userId",
76+
attributes: attributes) {
77+
print("[getFeatureVariableInteger] \(value)")
78+
}
79+
80+
if let value = try? optimizely.getFeatureVariableString(featureKey: "featureKey",
81+
variableKey: "kString",
82+
userId: "userId",
83+
attributes: attributes) {
84+
print("[getFeatureVariableString] \(value)")
85+
}
86+
87+
if let features = try? optimizely.getEnabledFeatures(userId: "userId", attributes: attributes) {
88+
print("[getEnabledFeatures] \(features)")
89+
}
90+
91+
try? optimizely.track(eventKey: "eventKey", userId: "userId", attributes: attributes, eventTags: eventTags)
92+
}
93+
94+
95+
}

0 commit comments

Comments
 (0)