Skip to content

Commit 9f8acb5

Browse files
Merge pull request #247 from Automattic/wcios/optional-variation
Experiment Variation - Return optional instead of `control`
2 parents a0efa79 + f990056 commit 9f8acb5

File tree

6 files changed

+10
-8
lines changed

6 files changed

+10
-8
lines changed

Automattic-Tracks-iOS.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = 'Automattic-Tracks-iOS'
5-
s.version = '1.0.0'
5+
s.version = '1.1.0-beta'
66

77
s.summary = 'Simple way to track events in an iOS app with Automattic Tracks internal service'
88
s.description = <<-DESC

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ _None._
3636

3737
- `logErrorImmediately` and `logErrorsImmediately` no longer have a `Result` parameter in their callback [#232]
3838
- `logErrorImmediately` and `logErrorsImmediately` no longer `throws` [#236]
39+
- `ExPlat` returns optional instead of assuming `control` as variant. This lets the client know that there is no variant for an experiment. [#247]
3940

4041
### New Features
4142

@@ -49,3 +50,4 @@ _None._
4950

5051
- Add this changelog file [#234]
5152
- Log a message if events won't be collected because the user opted out [#239]
53+
- Make `Variation` confirm to cobable. [#247]

Sources/Experiments/ABTesting.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
public enum Variation: Equatable {
3+
public enum Variation: Equatable, Codable {
44
case control
55
case treatment
66
case customTreatment(name: String)
@@ -13,5 +13,5 @@ public protocol ABTesting {
1313
func refresh(completion: (() -> Void)?)
1414

1515
/// Return an experiment variation
16-
func experiment(_ name: String) -> Variation
16+
func experiment(_ name: String) -> Variation?
1717
}

Sources/Experiments/ExPlat.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ import Cocoa
9595
}
9696
}
9797

98-
public func experiment(_ name: String) -> Variation {
98+
public func experiment(_ name: String) -> Variation? {
9999
guard let assignments = UserDefaults.standard.object(forKey: assignmentsKey) as? [String: String?],
100100
case let variation?? = assignments[name] else {
101-
return .control
101+
return nil
102102
}
103103

104104
switch variation {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#import "TracksConstants.h"
22

33
NSString *const TracksErrorDomain = @"TracksErrorDomain";
4-
NSString *const TracksLibraryVersion = @"1.0.0";
4+
NSString *const TracksLibraryVersion = @"1.1.0-beta";

Tests/Tests/ABTesting/ExPlatTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ExPlatTests: XCTestCase {
2121
let abTesting = ExPlat(configuration: exPlatTestConfiguration, service: ExPlatServiceMock())
2222

2323
abTesting.refresh {
24-
XCTAssertEqual(abTesting.experiment("experiment"), .control)
24+
XCTAssertNil(abTesting.experiment("experiment"))
2525
XCTAssertEqual(abTesting.experiment("another_experiment"), .treatment)
2626
XCTAssertEqual(abTesting.experiment("experiment_multiple_variation"), .customTreatment(name: "another_treatment"))
2727
expectation.fulfill()
@@ -70,7 +70,7 @@ class ExPlatTests: XCTestCase {
7070

7171
serviceMock.returnAssignments = false
7272
abTesting.refresh {
73-
XCTAssertEqual(abTesting.experiment("experiment"), .control)
73+
XCTAssertNil(abTesting.experiment("experiment"))
7474
XCTAssertEqual(abTesting.experiment("another_experiment"), .treatment)
7575
XCTAssertEqual(abTesting.experiment("experiment_multiple_variation"), .customTreatment(name: "another_treatment"))
7676
expectation.fulfill()

0 commit comments

Comments
 (0)