A Swift A/B testing framework for iOS
A/B testing (also known as split testing) is a good practice to test new concepts. Gollum is a A/B testing framework easy to use and inspired on some best practices in Swift, like:
- Value Types (structs and enums)
- Error Handling (ErrorType and throws)
- Compile time feedback
Add to your Podfile
:
pod 'Gollum'
Then run the command below:
$ pod install
Create a enum
with Version
type for your A/B test. Pass on each case a string with version name (e.g. A
) and its probability (e.g. 0.5
), both separated by :
.
enum MyABTest: Version {
case A = "A:0.5"
case B = "B:0.5"
}
Register the test's cases in Gollum:
try Gollum.instance.registerVersions([MyABTest.A, MyABTest.B])
After registration, you can check which version was selected using getSelectedVersion
:
switch try! Gollum.instance.getSelectedVersion(MyAdorableABTest) {
case .A:
view.backgroundColor = UIColor.redColor()
case .B:
view.backgroundColor = UIColor.greenColor()
}
Or using isVersionSelected
:
if try! Gollum.instance.isVersionSelected(MyAdorableABTest.A) {
view.backgroundColor = UIColor.redColor()
} else if try! Gollum.instance.isVersionSelected(MyAdorableABTest.B) {
view.backgroundColor = UIColor.greenColor()
}
To avoid unexpected scenarios during an A/B testing, it's important treat errors. Gollum can throw these errors:
public enum GollumError: ErrorType {
case VersionSyntaxError(String)
case ProbabilitySumIncorrect(String)
case EmptyVersionArrayPassed(String)
case SelectedVersionNotFound(String)
}
If an A/B testing enum is created with wrong syntax, like missing version name or probability, the application will crash with error VersionSyntaxError
:
enum MyABTest: Version {
case A = ":0.5"
case B = "B:0.5"
}
Error message:
fatal error: 'try!' expression unexpectedly raised an error: Gollum.GollumError.VersionSyntaxError("ABTest case expression must have name and probability values splitted by : (e.g. \"MyTestCaseA:0.5\")")
During an A/B test registration, the method registerVersions
can throws EmptyVersionArrayPassed
, SelectedVersionNotFound
or ProbabilitySumIncorrect
errors.
Also methods getSelectedVersion
and isVersionSelected
can throw SelectedVersionNotFound
error.
Because of some Swift's features, Gollum doesn't work in Objective-C.
Gollum is available under the MIT license. See the LICENSE file for more info.