Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 22 additions & 31 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ Carthage/Build
# This was causing confusion on PRs and is really just a record of the last time the example
# pods were re-built from scratch. It's not useful to keep in the repo.
Example/Podfile.lock

# Test configuration with real API keys (do not commit)
FlagsmithClient/Tests/test-config.json
139 changes: 139 additions & 0 deletions AppDelegate.swift
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()
}

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
}
28 changes: 20 additions & 8 deletions Example/FlagsmithClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 77;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -201,13 +201,16 @@
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-FlagsmithClient_Example/Pods-FlagsmithClient_Example-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)";
Expand All @@ -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)";
Expand Down
2 changes: 1 addition & 1 deletion Example/FlagsmithClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
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 settings page>"
Flagsmith.shared.apiKey = "<add your API key from the Flagsmith dashboard here>"

// set default flags
Flagsmith.shared.defaultFlags = [Flag(featureName: "feature_a", enabled: false),
Expand Down
Loading
Loading