-
Notifications
You must be signed in to change notification settings - Fork 15
fix: Cache Functionality Fixes and Comprehensive Test Suite #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,48 +7,39 @@ on: | |
| branches: [main] | ||
|
|
||
| jobs: | ||
| macos-build-14: | ||
| macos-latest: | ||
| # macOS-latest images are not the most recent | ||
| # The macos-latest workflow label currently uses the macOS 12 runner image, which doesn't include the build-tools we need | ||
| # The vast majority of macOS developers would be using the latest version of macOS | ||
| # Current list here: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners | ||
| runs-on: macOS-14 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Build (macOS) | ||
| run: swift build -v | ||
| - name: Run tests | ||
| run: swift test -v | ||
|
|
||
| macos-build-13: | ||
| # Let's also check that the code builds on macOS 13 | ||
| # At 23rd April 2023 the 'latest' macOS version is macOS 12 | ||
| runs-on: macOS-13 | ||
|
|
||
| runs-on: macOS-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Check for FLAGSMITH_TEST_API_KEY | ||
| run: | | ||
| if [ -z "$FLAGSMITH_TEST_API_KEY" ]; then | ||
| echo "Warning: FLAGSMITH_TEST_API_KEY environment variable is not set" | ||
| exit 1 | ||
| fi | ||
| env: | ||
| FLAGSMITH_TEST_API_KEY: ${{ secrets.FLAGSMITH_TEST_API_KEY }} | ||
| - name: Build (macOS) | ||
| run: swift build -v | ||
| - name: Run tests | ||
| run: swift test -v | ||
|
|
||
| ubuntu-build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Build (Ubuntu) | ||
| run: swift build -v | ||
| run: swift --version && swift build | ||
| - name: Run tests | ||
| run: swift test -v | ||
|
|
||
| run: swift test | ||
| env: | ||
| FLAGSMITH_TEST_API_KEY: ${{ secrets.FLAGSMITH_TEST_API_KEY }} | ||
| swift-lint: | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Check for FLAGSMITH_TEST_API_KEY | ||
| run: | | ||
| if [ -z "$FLAGSMITH_TEST_API_KEY" ]; then | ||
| echo "Warning: FLAGSMITH_TEST_API_KEY environment variable is not set" | ||
| exit 1 | ||
| fi | ||
| env: | ||
| FLAGSMITH_TEST_API_KEY: ${{ secrets.FLAGSMITH_TEST_API_KEY }} | ||
|
|
||
| - name: Run SwiftLint | ||
| uses: norio-nomura/[email protected] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| // | ||
| // AppDelegate.swift | ||
| // FlagsmithClient | ||
| // | ||
| // Created by Tomash Tsiupiak on 06/20/2019. | ||
| // Copyright (c) 2019 Tomash Tsiupiak. All rights reserved. | ||
| // | ||
|
|
||
| import UIKit | ||
| import FlagsmithClient | ||
| #if canImport(SwiftUI) | ||
| import SwiftUI | ||
| #endif | ||
|
|
||
| func isSuccess<T, F>(_ result: Result<T, F>) -> Bool { | ||
| if case .success = result { return true } else { return false } | ||
| } | ||
|
|
||
| @UIApplicationMain | ||
| class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
|
||
| var window: UIWindow? | ||
| let concurrentQueue = DispatchQueue(label: "concurrentQueue", qos: .default, attributes: .concurrent) | ||
|
|
||
| func application(_ application: UIApplication, | ||
| didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
| // Override point for customization after application launch. | ||
| Flagsmith.shared.apiKey = "<add your API key from the Flagsmith dashboard here>" | ||
|
|
||
| // set default flags | ||
| Flagsmith.shared.defaultFlags = [Flag(featureName: "feature_a", enabled: false), | ||
| Flag(featureName: "font_size", intValue: 12, enabled: true), | ||
| Flag(featureName: "my_name", stringValue: "Testing", enabled: true)] | ||
|
|
||
| // set cache on / off (defaults to off) | ||
| Flagsmith.shared.cacheConfig.useCache = true | ||
|
|
||
| // set custom cache to use (defaults to shared URLCache) | ||
| // Flagsmith.shared.cacheConfig.cache = <CUSTOM_CACHE> | ||
|
|
||
| // set skip API on / off (defaults to off) | ||
| Flagsmith.shared.cacheConfig.skipAPI = false | ||
|
|
||
| // set cache TTL in seconds (defaults to 0, i.e. infinite) | ||
| Flagsmith.shared.cacheConfig.cacheTTL = 90 | ||
|
|
||
| // set analytics on or off | ||
| Flagsmith.shared.enableAnalytics = true | ||
|
|
||
| // Enable real time updates | ||
| Flagsmith.shared.enableRealtimeUpdates = true | ||
|
|
||
| // set the analytics flush period in seconds | ||
| Flagsmith.shared.analyticsFlushPeriod = 10 | ||
|
|
||
| Flagsmith.shared.getFeatureFlags { (result) in | ||
| print(result) | ||
| } | ||
| Flagsmith.shared.hasFeatureFlag(withID: "freeze_delinquent_accounts") { (result) in | ||
| print(result) | ||
| } | ||
|
|
||
| // Try getting the feature flags concurrently to ensure that this does not cause any issues | ||
| // This was originally highlighted in https://github.com/Flagsmith/flagsmith-ios-client/pull/40 | ||
| for _ in 1...20 { | ||
| concurrentQueue.async { | ||
| Flagsmith.shared.getFeatureFlags { (_) in | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Flagsmith.shared.setTrait(Trait(key: "<my_key>", value: "<my_value>"), forIdentity: "<my_identity>") { (result) in print(result) } | ||
| // Flagsmith.shared.getIdentity("<my_key>") { (result) in print(result) } | ||
matthewelwell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Launch SwiftUIView | ||
| if #available(iOS 13.0, *) { | ||
| let swiftUIView = SwiftUIView() | ||
| window = UIWindow(frame: UIScreen.main.bounds) | ||
| window?.rootViewController = UIHostingController(rootView: swiftUIView) | ||
| window?.makeKeyAndVisible() | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| func applicationWillResignActive(_ application: UIApplication) { | ||
| // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
| // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | ||
| } | ||
|
|
||
| func applicationDidEnterBackground(_ application: UIApplication) { | ||
| // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
| // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | ||
| } | ||
|
|
||
| func applicationWillEnterForeground(_ application: UIApplication) { | ||
| // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. | ||
| } | ||
|
|
||
| func applicationDidBecomeActive(_ application: UIApplication) { | ||
| // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
| } | ||
|
|
||
| func applicationWillTerminate(_ application: UIApplication) { | ||
| // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. | ||
| } | ||
|
|
||
| #if swift(>=5.5.2) | ||
| /// (Example) Setup the app based on the available feature flags. | ||
| /// | ||
| /// **Flagsmith** supports the Swift Concurrency feature `async`/`await`. | ||
| /// Requests and logic can be handled in a streamlined order, | ||
| /// eliminating the need to nest multiple completion handlers. | ||
| @available(iOS 13.0, *) | ||
| func determineAppConfiguration() async { | ||
| let flagsmith = Flagsmith.shared | ||
|
|
||
| do { | ||
| if try await flagsmith.hasFeatureFlag(withID: "ab_test_enabled") { | ||
| if let theme = try await flagsmith.getValueForFeature(withID: "app_theme") { | ||
| setTheme(theme) | ||
| } else { | ||
| let flags = try await flagsmith.getFeatureFlags() | ||
| processFlags(flags) | ||
| } | ||
| } else { | ||
| let trait = Trait(key: "selected_tint_color", value: "orange") | ||
| let identity = "4DDBFBCA-3B6E-4C59-B107-954F84FD7F6D" | ||
| try await flagsmith.setTrait(trait, forIdentity: identity) | ||
| } | ||
| } catch { | ||
| print(error) | ||
| } | ||
| } | ||
|
|
||
| func setTheme(_ theme: TypedValue) {} | ||
| func processFlags(_ flags: [Flag]) {} | ||
| #endif | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.