Skip to content

Commit

Permalink
Merge pull request #1 from configcat/improvements
Browse files Browse the repository at this point in the history
Improvements: Comparators, Semantic Version, Verbose logging, config_v3.json
  • Loading branch information
ConfigCat authored Nov 29, 2019
2 parents 376a866 + 4962768 commit 58c19d3
Show file tree
Hide file tree
Showing 18 changed files with 934 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "Version/*.swift"
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
- stage: test
script:
- set -o pipefail
- xcodebuild clean test -sdk iphonesimulator12.0 -project ConfigCat.xcodeproj -scheme "ConfigCat iOS" -destination "OS=12.0,name=iPhone 8" CODE_SIGNING_REQUIRED=NO
- xcodebuild clean test -sdk appletvsimulator12.0 -project ConfigCat.xcodeproj -scheme "ConfigCat tvOS" -destination "OS=12.0,name=Apple TV 4K (at 1080p)" CODE_SIGNING_REQUIRED=NO
- xcodebuild clean test -sdk macosx10.14 -project ConfigCat.xcodeproj -scheme "ConfigCat macOS" -destination "arch=x86_64"
- xcodebuild clean test -sdk iphonesimulator12.0 -project ConfigCat.xcodeproj -scheme "ConfigCat iOS" -destination "OS=12.0,name=iPhone 8" CODE_SIGNING_REQUIRED=NO -quiet
- xcodebuild clean test -sdk appletvsimulator12.0 -project ConfigCat.xcodeproj -scheme "ConfigCat tvOS" -destination "OS=12.0,name=Apple TV 4K (at 1080p)" CODE_SIGNING_REQUIRED=NO -quiet
- xcodebuild clean test -sdk macosx10.14 -project ConfigCat.xcodeproj -scheme "ConfigCat macOS" -destination "arch=x86_64" -quiet

- stage: coverage
script:
- set -o pipefail
- xcodebuild clean test -sdk macosx10.14 -project ConfigCat.xcodeproj -scheme "ConfigCat Coverage" -destination "arch=x86_64"
- xcodebuild clean test -sdk macosx10.14 -project ConfigCat.xcodeproj -scheme "ConfigCat Coverage" -destination "arch=x86_64" -quiet
- bash <(curl -s https://codecov.io/bash)

- stage: lint
Expand Down
4 changes: 2 additions & 2 deletions ConfigCat.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pod::Spec.new do |spec|
spec.summary = "ConfigCat Swift SDK"
spec.swift_version = "4.2"

spec.description = "ConfigCat is a feature flag, feature toggle, and configuration management service. That lets you launch new features and change your software configuration remotely without actually (re)deploying code. ConfigCat even helps you do controlled roll-outs like canary releases and blue-green deployments."
spec.description = "Feature Flags created by developers for developers with ❤️. ConfigCat lets you manage feature flags across frontend, backend, mobile, and desktop apps without (re)deploying code. % rollouts, user targeting, segmentation. Feature toggle SDKs for all main languages. Alternative to LaunchDarkly. Host yourself, or use the hosted management app at https://configcat.com."
spec.homepage = "https://github.com/configcat/swift-sdk"
spec.license = { :type => "MIT", :file => "LICENSE" }
spec.author = { "ConfigCat" => "[email protected]" }
Expand All @@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
spec.osx.deployment_target = '10.12'

spec.source = { :git => "https://github.com/configcat/swift-sdk.git", :tag => spec.version }
spec.source_files = "Sources/*.swift"
spec.source_files = "Sources/*.swift", "Version/*.swift"
spec.requires_arc = true
spec.module_name = "ConfigCat"
spec.documentation_url = "https://docs.configcat.com/docs/sdk-reference/ios"
Expand Down
65 changes: 65 additions & 0 deletions ConfigCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@
objects = {

/* Begin PBXBuildFile section */
1A3B096723909055002A3A62 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096423909055002A3A62 /* Version.swift */; };
1A3B096823909056002A3A62 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096423909055002A3A62 /* Version.swift */; };
1A3B096923909056002A3A62 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096423909055002A3A62 /* Version.swift */; };
1A3B096A23909056002A3A62 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096423909055002A3A62 /* Version.swift */; };
1A3B096B23909056002A3A62 /* Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096523909055002A3A62 /* Regex.swift */; };
1A3B096C23909056002A3A62 /* Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096523909055002A3A62 /* Regex.swift */; };
1A3B096D23909056002A3A62 /* Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096523909055002A3A62 /* Regex.swift */; };
1A3B096E23909056002A3A62 /* Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096523909055002A3A62 /* Regex.swift */; };
1A3B096F23909056002A3A62 /* VersionParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096623909055002A3A62 /* VersionParser.swift */; };
1A3B097023909056002A3A62 /* VersionParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096623909055002A3A62 /* VersionParser.swift */; };
1A3B097123909056002A3A62 /* VersionParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096623909055002A3A62 /* VersionParser.swift */; };
1A3B097223909056002A3A62 /* VersionParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B096623909055002A3A62 /* VersionParser.swift */; };
1AEDBE8323876064008803E7 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AEDBE8223876064008803E7 /* Config.swift */; };
1AEDBE8423876064008803E7 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AEDBE8223876064008803E7 /* Config.swift */; };
1AEDBE8523876064008803E7 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AEDBE8223876064008803E7 /* Config.swift */; };
1AEDBE8623876064008803E7 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AEDBE8223876064008803E7 /* Config.swift */; };
1AEDBE9B238761BA008803E7 /* testmatrix_semantic.csv in Resources */ = {isa = PBXBuildFile; fileRef = 1AEDBE98238761BA008803E7 /* testmatrix_semantic.csv */; };
1AEDBE9D238761BA008803E7 /* testmatrix_semantic.csv in Resources */ = {isa = PBXBuildFile; fileRef = 1AEDBE98238761BA008803E7 /* testmatrix_semantic.csv */; };
1AEDBE9F238761BA008803E7 /* testmatrix_semantic.csv in Resources */ = {isa = PBXBuildFile; fileRef = 1AEDBE98238761BA008803E7 /* testmatrix_semantic.csv */; };
1AEDBEA2238761BA008803E7 /* testmatrix_number.csv in Resources */ = {isa = PBXBuildFile; fileRef = 1AEDBE99238761BA008803E7 /* testmatrix_number.csv */; };
1AEDBEA4238761BA008803E7 /* testmatrix_number.csv in Resources */ = {isa = PBXBuildFile; fileRef = 1AEDBE99238761BA008803E7 /* testmatrix_number.csv */; };
1AEDBEA6238761BA008803E7 /* testmatrix_number.csv in Resources */ = {isa = PBXBuildFile; fileRef = 1AEDBE99238761BA008803E7 /* testmatrix_number.csv */; };
3F36F5392083D5C400949B8F /* LazyLoadingSyncTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F36F5382083D5C400949B8F /* LazyLoadingSyncTests.swift */; };
3F36F53A2083D5C400949B8F /* LazyLoadingSyncTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F36F5382083D5C400949B8F /* LazyLoadingSyncTests.swift */; };
3F36F53B2083D5C400949B8F /* LazyLoadingSyncTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F36F5382083D5C400949B8F /* LazyLoadingSyncTests.swift */; };
Expand Down Expand Up @@ -120,6 +142,12 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1A3B096423909055002A3A62 /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Version.swift; path = Version/Version.swift; sourceTree = SOURCE_ROOT; };
1A3B096523909055002A3A62 /* Regex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Regex.swift; path = Version/Regex.swift; sourceTree = SOURCE_ROOT; };
1A3B096623909055002A3A62 /* VersionParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = VersionParser.swift; path = Version/VersionParser.swift; sourceTree = SOURCE_ROOT; };
1AEDBE8223876064008803E7 /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
1AEDBE98238761BA008803E7 /* testmatrix_semantic.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = testmatrix_semantic.csv; sourceTree = "<group>"; };
1AEDBE99238761BA008803E7 /* testmatrix_number.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = testmatrix_number.csv; sourceTree = "<group>"; };
3F029E89207EB3BD0019942F /* Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mock.swift; sourceTree = "<group>"; };
3F36F5382083D5C400949B8F /* LazyLoadingSyncTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazyLoadingSyncTests.swift; sourceTree = "<group>"; };
3F36F53C2083DA3600949B8F /* LazyLoadingAsyncTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazyLoadingAsyncTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -215,9 +243,21 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
1AEDBE97238760A4008803E7 /* Version */ = {
isa = PBXGroup;
children = (
1A3B096523909055002A3A62 /* Regex.swift */,
1A3B096423909055002A3A62 /* Version.swift */,
1A3B096623909055002A3A62 /* VersionParser.swift */,
);
name = Version;
path = Sources;
sourceTree = "<group>";
};
3F8809CB207BE3F100087A6B = {
isa = PBXGroup;
children = (
1AEDBE97238760A4008803E7 /* Version */,
3F880A43207BE92000087A6B /* Tests */,
3F880A42207BE91900087A6B /* Sources */,
3F880A41207BE91300087A6B /* Assets */,
Expand Down Expand Up @@ -254,6 +294,7 @@
3F880A42207BE91900087A6B /* Sources */ = {
isa = PBXGroup;
children = (
1AEDBE8223876064008803E7 /* Config.swift */,
3F880A9E207BF1B100087A6B /* AsyncResult.swift */,
3F880AA0207BF1B100087A6B /* AutoPollingPolicy.swift */,
3F880AA1207BF1B100087A6B /* ConfigCache.swift */,
Expand All @@ -274,6 +315,8 @@
3F880A43207BE92000087A6B /* Tests */ = {
isa = PBXGroup;
children = (
1AEDBE99238761BA008803E7 /* testmatrix_number.csv */,
1AEDBE98238761BA008803E7 /* testmatrix_semantic.csv */,
F15F9B122169738100F490CD /* testmatrix.csv */,
3F880A83207BEEEB00087A6B /* Info-tvOS.plist */,
3F880A58207BECB100087A6B /* Info-macOS.plist */,
Expand Down Expand Up @@ -532,6 +575,8 @@
buildActionMask = 2147483647;
files = (
F15F9B132169738100F490CD /* testmatrix.csv in Resources */,
1AEDBEA2238761BA008803E7 /* testmatrix_number.csv in Resources */,
1AEDBE9B238761BA008803E7 /* testmatrix_semantic.csv in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -547,6 +592,8 @@
buildActionMask = 2147483647;
files = (
F15F9B142169738100F490CD /* testmatrix.csv in Resources */,
1AEDBEA4238761BA008803E7 /* testmatrix_number.csv in Resources */,
1AEDBE9D238761BA008803E7 /* testmatrix_semantic.csv in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -562,6 +609,8 @@
buildActionMask = 2147483647;
files = (
F15F9B152169738100F490CD /* testmatrix.csv in Resources */,
1AEDBEA6238761BA008803E7 /* testmatrix_number.csv in Resources */,
1AEDBE9F238761BA008803E7 /* testmatrix_semantic.csv in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -580,8 +629,12 @@
buildActionMask = 2147483647;
files = (
3F880ACE207C072400087A6B /* ConfigCatClient.swift in Sources */,
1A3B096B23909056002A3A62 /* Regex.swift in Sources */,
1A3B096723909055002A3A62 /* Version.swift in Sources */,
3F880AA7207BF1B100087A6B /* ConfigFetcher.swift in Sources */,
3F880AA4207BF1B100087A6B /* LazyLoadingPolicy.swift in Sources */,
1A3B096F23909056002A3A62 /* VersionParser.swift in Sources */,
1AEDBE8323876064008803E7 /* Config.swift in Sources */,
F15F9AFC216922F000F490CD /* RolloutEvaluator.swift in Sources */,
3F880AA8207BF1B100087A6B /* AutoPollingPolicy.swift in Sources */,
3F880AA6207BF1B100087A6B /* AsyncResult.swift in Sources */,
Expand Down Expand Up @@ -615,8 +668,12 @@
buildActionMask = 2147483647;
files = (
3F880ACF207C072400087A6B /* ConfigCatClient.swift in Sources */,
1A3B096C23909056002A3A62 /* Regex.swift in Sources */,
1A3B096823909056002A3A62 /* Version.swift in Sources */,
3F880AB0207BF2A100087A6B /* LazyLoadingPolicy.swift in Sources */,
3F880AB1207BF2A100087A6B /* RefreshPolicy.swift in Sources */,
1A3B097023909056002A3A62 /* VersionParser.swift in Sources */,
1AEDBE8423876064008803E7 /* Config.swift in Sources */,
F15F9AFD216922F000F490CD /* RolloutEvaluator.swift in Sources */,
3F880AAC207BF2A100087A6B /* AutoPollingPolicy.swift in Sources */,
3F880AAE207BF2A100087A6B /* ConfigFetcher.swift in Sources */,
Expand Down Expand Up @@ -650,8 +707,12 @@
buildActionMask = 2147483647;
files = (
3F880AD0207C072400087A6B /* ConfigCatClient.swift in Sources */,
1A3B096D23909056002A3A62 /* Regex.swift in Sources */,
1A3B096923909056002A3A62 /* Version.swift in Sources */,
3F880AB8207BF2A200087A6B /* LazyLoadingPolicy.swift in Sources */,
3F880AB9207BF2A200087A6B /* RefreshPolicy.swift in Sources */,
1A3B097123909056002A3A62 /* VersionParser.swift in Sources */,
1AEDBE8523876064008803E7 /* Config.swift in Sources */,
F15F9AFE216922F000F490CD /* RolloutEvaluator.swift in Sources */,
3F880AB4207BF2A200087A6B /* AutoPollingPolicy.swift in Sources */,
3F880AB6207BF2A200087A6B /* ConfigFetcher.swift in Sources */,
Expand Down Expand Up @@ -685,8 +746,12 @@
buildActionMask = 2147483647;
files = (
3F880AD1207C072400087A6B /* ConfigCatClient.swift in Sources */,
1A3B096E23909056002A3A62 /* Regex.swift in Sources */,
1A3B096A23909056002A3A62 /* Version.swift in Sources */,
3F880AC0207BF2A300087A6B /* LazyLoadingPolicy.swift in Sources */,
3F880AC1207BF2A300087A6B /* RefreshPolicy.swift in Sources */,
1A3B097223909056002A3A62 /* VersionParser.swift in Sources */,
1AEDBE8623876064008803E7 /* Config.swift in Sources */,
F15F9AFF216922F000F490CD /* RolloutEvaluator.swift in Sources */,
3F880ABC207BF2A300087A6B /* AutoPollingPolicy.swift in Sources */,
3F880ABE207BF2A300087A6B /* ConfigFetcher.swift in Sources */,
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ client.getValueAsync(for: "isMyAwesomeFeatureEnabled", defaultValue: false, comp
## Getting user specific setting values with Targeting
Using this feature, you will be able to get different setting values for different users in your application by passing a `User Object` to the `getValue()` function.

Read more about [Targeting here](https://docs.configcat.com/docs/advanced/targeting/).
Read more about [Targeting here](https://configcat.com/docs/advanced/targeting/).

```swift
let user = User(identifier: "#USER-IDENTIFIER#")
Expand All @@ -91,7 +91,7 @@ if(isMyAwesomeFeatureEnabled) {
[Sample iOS app](https://github.com/configcat/swift-sdk/tree/master/samples/ios)

## Polling Modes
The ConfigCat SDK supports 3 different polling mechanisms to acquire the setting values from ConfigCat. After latest setting values are downloaded, they are stored in the internal cache then all requests are served from there. Read more about Polling Modes and how to use them at [ConfigCat Docs](https://docs.configcat.com/docs/sdk-reference/ios/).
The ConfigCat SDK supports 3 different polling mechanisms to acquire the setting values from ConfigCat. After latest setting values are downloaded, they are stored in the internal cache then all requests are served from there. Read more about Polling Modes and how to use them at [ConfigCat Docs](https://configcat.com/docs/sdk-reference/ios/).

## Support
If you need help how to use this SDK feel free to to contact the ConfigCat Staff on https://configcat.com. We're happy to help.
Expand All @@ -100,6 +100,6 @@ If you need help how to use this SDK feel free to to contact the ConfigCat Staff
Contributions are welcome.

## About ConfigCat
- [Official ConfigCat SDK's for other platforms](https://github.com/configcat)
- [Documentation](https://docs.configcat.com)
- [Blog](https://blog.configcat.com)
- [Official ConfigCat SDKs for other platforms](https://github.com/configcat)
- [Documentation](https://configcat.com/docs)
- [Blog](https://configcat.com/blog)
9 changes: 9 additions & 0 deletions Sources/Config.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enum Config {
static let value = "v"
static let comparator = "t"
static let comparisonAttribute = "a"
static let comparisonValue = "c"
static let rolloutPercentageItems = "p"
static let percentage = "p"
static let rolloutRules = "r"
}
6 changes: 4 additions & 2 deletions Sources/ConfigFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class ConfigFetcher : NSObject {
public init(session: URLSession, apiKey: String, baseUrl: String = "") {
let base = baseUrl.isEmpty ? "https://cdn.configcat.com" : baseUrl
self.session = session
self.url = base + "/configuration-files/" + apiKey + "/config_v2.json"
self.url = base + "/configuration-files/" + apiKey + "/config_v3.json"
self.etag = ""
self.mode = ""
}
Expand Down Expand Up @@ -108,7 +108,9 @@ public class ConfigFetcher : NSObject {
os_log("Fetch was successful: not modified", log: ConfigFetcher.log, type: .debug)
result.complete(result: FetchResponse(status: .notModified, body: ""))
} else {
os_log("Non success status code: %@", log: ConfigFetcher.log, type: .error, String(response.statusCode))
os_log("""
Double-check your API KEY at https://app.configcat.com/apikey. Non success status code: %@
""", log: ConfigFetcher.log, type: .error, String(response.statusCode))
result.complete(result: FetchResponse(status: .failure, body: ""))
}
}
Expand Down
12 changes: 9 additions & 3 deletions Sources/ConfigParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ public final class ConfigParser {
}

if let data = json.data(using: .utf8) {
if let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let value: Value = self.evaluator.evaluate(json: jsonObject[key], key: key, user: user) {
if let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
if let value: Value = self.evaluator.evaluate(json: jsonObject[key], key: key, user: user) {
return value
} else {
os_log("""
Parsing the json value for the key '%@' failed.
Returning defaultValue.
Here are the available keys: %@
""", log: ConfigParser.log, type: .error, key, [String](jsonObject.keys))
}
}
}

os_log("Parsing the json value for the key '%@' failed.", log: ConfigParser.log, type: .error, key)
throw ParserError.parseFailure
}

Expand Down
Loading

0 comments on commit 58c19d3

Please sign in to comment.