-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Cache Functionality Fixes and Comprehensive Test Suite #3
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
base: main
Are you sure you want to change the base?
Changes from all commits
78d4205
52078dd
c9a3180
7ff413b
91ce986
4254dbe
5968ff9
8d0b167
ff60586
66594a7
bf5c8ff
baeddb4
832ee23
26c1cac
0123ace
500867e
a27ffc0
551e41e
9d32672
c9ec285
04aab47
53fe239
98aad17
02169d2
1cb0740
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Launch SwiftUIView | ||||||||||||||||||||||||||||||||||
| if #available(iOS 13.0, *) { | ||||||||||||||||||||||||||||||||||
| let swiftUIView = SwiftUIView() | ||||||||||||||||||||||||||||||||||
| window = UIWindow(frame: UIScreen.main.bounds) | ||||||||||||||||||||||||||||||||||
| window?.rootViewController = UIHostingController(rootView: swiftUIView) | ||||||||||||||||||||||||||||||||||
| window?.makeKeyAndVisible() | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+75
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard SwiftUI usage with canImport to prevent build failures on toolchains without SwiftUI.
- // Launch SwiftUIView
- if #available(iOS 13.0, *) {
- let swiftUIView = SwiftUIView()
- window = UIWindow(frame: UIScreen.main.bounds)
- window?.rootViewController = UIHostingController(rootView: swiftUIView)
- window?.makeKeyAndVisible()
- }
+ // Launch SwiftUIView
+ #if canImport(SwiftUI)
+ if #available(iOS 13.0, *) {
+ let swiftUIView = SwiftUIView()
+ window = UIWindow(frame: UIScreen.main.bounds)
+ window?.rootViewController = UIHostingController(rootView: swiftUIView)
+ window?.makeKeyAndVisible()
+ }
+ #endif📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| archiveVersion = 1; | ||
| classes = { | ||
| }; | ||
| objectVersion = 46; | ||
| objectVersion = 77; | ||
| objects = { | ||
|
|
||
| /* Begin PBXBuildFile section */ | ||
|
|
@@ -143,14 +143,14 @@ | |
| }; | ||
| }; | ||
| buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "FlagsmithClient" */; | ||
| compatibilityVersion = "Xcode 3.2"; | ||
| developmentRegion = en; | ||
| hasScannedForEncodings = 0; | ||
| knownRegions = ( | ||
| en, | ||
| Base, | ||
| ); | ||
| mainGroup = 607FACC71AFB9204008FA782; | ||
| preferredProjectObjectVersion = 77; | ||
| productRefGroup = 607FACD11AFB9204008FA782 /* Products */; | ||
| projectDirPath = ""; | ||
| projectRoot = ""; | ||
|
|
@@ -201,13 +201,16 @@ | |
| buildActionMask = 2147483647; | ||
| files = ( | ||
| ); | ||
| inputFileListPaths = ( | ||
| "${PODS_ROOT}/Target Support Files/Pods-FlagsmithClient_Example/Pods-FlagsmithClient_Example-frameworks-${CONFIGURATION}-input-files.xcfilelist", | ||
| ); | ||
|
Comment on lines
+204
to
+206
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainSwitch to filelists for Embed Pods frameworks is good; ensure filelists exist. Using xcfilelists reduces merge noise. Verify the Debug/Release filelist files are present under Target Support Files. Also applies to: 210-212 🏁 Script executed: #!/bin/bash
fd -H --strip-cwd-prefix 'Pods-FlagsmithClient_Example-frameworks-*-(input|output)-files.xcfilelist' \
'Example/Pods/Target Support Files/Pods-FlagsmithClient_Example'Length of output: 166 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Checking for xcfilelist files for Pods-FlagsmithClient_Example..."
paths=(
"Example/Pods/Target Support Files/Pods-FlagsmithClient_Example"
"Pods/Target Support Files/Pods-FlagsmithClient_Example"
)
found=0
for p in "${paths[@]}"; do
if [ -d "$p" ]; then
echo "Directory exists: $p"
echo "Listing .xcfilelist files (maxdepth 1):"
find "$p" -maxdepth 1 -type f -iname "*.xcfilelist" -print -exec ls -l {} \; || true
echo "Listing files matching frameworks input/output patterns:"
find "$p" -maxdepth 1 -type f \( -iname "Pods-FlagsmithClient_Example-frameworks-*-input-files.xcfilelist" -o -iname "Pods-FlagsmithClient_Example-frameworks-*-output-files.xcfilelist" \) -print -exec ls -l {} \; || true
found=1
else
echo "Directory not found: $p"
fi
done
echo "Also searching the whole repo for any .xcfilelist files (will print matches):"
find . -type f -iname "*.xcfilelist" -print -exec ls -l {} \; || true
if [ "$found" -eq 0 ]; then
echo "No Target Support Files dirs found for Pods-FlagsmithClient_Example. Showing Example/ and Pods/ top-level directories for context:"
echo "---- Example/ ----"
ls -la Example || true
echo "---- Pods/ ----"
ls -la Pods || true
fiLength of output: 397 Missing .xcfilelist files referenced by project Example/FlagsmithClient.xcodeproj/project.pbxproj references ${PODS_ROOT}/Target Support Files/Pods-FlagsmithClient_Example/Pods-FlagsmithClient_Example-frameworks-${CONFIGURATION}-input-files.xcfilelist (lines 204–206; also applies to 210–212), but Example/Pods/Target Support Files/Pods-FlagsmithClient_Example contains no .xcfilelist files.
🤖 Prompt for AI Agents |
||
| inputPaths = ( | ||
| "${PODS_ROOT}/Target Support Files/Pods-FlagsmithClient_Example/Pods-FlagsmithClient_Example-frameworks.sh", | ||
| "${BUILT_PRODUCTS_DIR}/FlagsmithClient/FlagsmithClient.framework", | ||
| ); | ||
| name = "[CP] Embed Pods Frameworks"; | ||
| outputFileListPaths = ( | ||
| "${PODS_ROOT}/Target Support Files/Pods-FlagsmithClient_Example/Pods-FlagsmithClient_Example-frameworks-${CONFIGURATION}-output-files.xcfilelist", | ||
| ); | ||
| outputPaths = ( | ||
| "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FlagsmithClient.framework", | ||
| ); | ||
| runOnlyForDeploymentPostprocessing = 0; | ||
| shellPath = /bin/sh; | ||
|
|
@@ -350,7 +353,8 @@ | |
| IPHONEOS_DEPLOYMENT_TARGET = 14.0; | ||
| MTL_ENABLE_DEBUG_INFO = NO; | ||
| SDKROOT = iphoneos; | ||
| SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; | ||
| SWIFT_COMPILATION_MODE = wholemodule; | ||
| SWIFT_OPTIMIZATION_LEVEL = "-O"; | ||
| VALIDATE_PRODUCT = YES; | ||
| }; | ||
| name = Release; | ||
|
|
@@ -362,7 +366,11 @@ | |
| ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ||
| DEVELOPMENT_TEAM = RYCT86V4LM; | ||
| INFOPLIST_FILE = FlagsmithClient/Info.plist; | ||
| LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; | ||
| IPHONEOS_DEPLOYMENT_TARGET = 15.6; | ||
| LD_RUNPATH_SEARCH_PATHS = ( | ||
| "$(inherited)", | ||
| "@executable_path/Frameworks", | ||
| ); | ||
| MODULE_NAME = ExampleApp; | ||
| PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; | ||
| PRODUCT_NAME = "$(TARGET_NAME)"; | ||
|
|
@@ -377,7 +385,11 @@ | |
| ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ||
| DEVELOPMENT_TEAM = RYCT86V4LM; | ||
| INFOPLIST_FILE = FlagsmithClient/Info.plist; | ||
| LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; | ||
| IPHONEOS_DEPLOYMENT_TARGET = 15.6; | ||
| LD_RUNPATH_SEARCH_PATHS = ( | ||
| "$(inherited)", | ||
| "@executable_path/Frameworks", | ||
| ); | ||
| MODULE_NAME = ExampleApp; | ||
| PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; | ||
| PRODUCT_NAME = "$(TARGET_NAME)"; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.