Skip to content

Commit

Permalink
Merge branch 'main' into feature/strict-concurrency-split
Browse files Browse the repository at this point in the history
# Conflicts:
#	Example/FlagsmithClient/AppDelegate.swift
#	FlagsmithClient/Classes/Feature.swift
#	FlagsmithClient/Classes/Flag.swift
#	FlagsmithClient/Classes/Flagsmith.swift
#	FlagsmithClient/Classes/FlagsmithError.swift
#	FlagsmithClient/Classes/Internal/APIManager.swift
#	FlagsmithClient/Classes/Internal/FlagsmithAnalytics.swift
#	FlagsmithClient/Classes/Trait.swift
#	FlagsmithClient/Classes/TypedValue.swift
#	FlagsmithClient/Classes/UnknownTypeValue.swift
#	FlagsmithClient/Tests/APIManagerTests.swift
#	Package.swift
  • Loading branch information
gazreese committed May 2, 2024
2 parents 089b210 + 16bbfb0 commit f0e9df2
Show file tree
Hide file tree
Showing 22 changed files with 527 additions and 398 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ jobs:
run: swift build -v
- name: Run tests
run: swift test -v

swift-lint:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Run SwiftLint
uses: norio-nomura/[email protected]
# TODO: enable these settings:
# env:
# DIFF_BASE: ${{ github.base_ref }}
# with:
# args: --strict
1 change: 1 addition & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--disable redundantInternal
17 changes: 17 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- .build

disabled_rules: # rule identifiers to exclude from running
- nesting
- trailing_whitespace
- opening_brace
- trailing_comma

line_length:
warning: 140
error: 160
ignores_comments: true
ignores_urls: true


53 changes: 27 additions & 26 deletions Example/FlagsmithClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,31 @@
import UIKit
import FlagsmithClient

func isSuccess<T,F>(_ result: Result<T,F>) -> Bool {
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 {

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>"

// 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)]
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>
// Flagsmith.shared.cacheConfig.cache = <CUSTOM_CACHE>

// set skip API on / off (defaults to off)
Flagsmith.shared.cacheConfig.skipAPI = false
Expand All @@ -42,53 +43,53 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// set analytics on or off
Flagsmith.shared.enableAnalytics = true

// set the analytics flush period in seconds
Flagsmith.shared.analyticsFlushPeriod = 10
Flagsmith.shared.getFeatureFlags() { (result) in

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() { (result) in
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) }

// 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) }
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.
///
Expand All @@ -98,7 +99,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
@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") {
Expand All @@ -116,7 +117,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print(error)
}
}

func setTheme(_ theme: TypedValue) {}
func processFlags(_ flags: [Flag]) {}
#endif
Expand Down
12 changes: 1 addition & 11 deletions Example/FlagsmithClient/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,5 @@ import UIKit
import FlagsmithClient

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}
40 changes: 17 additions & 23 deletions FlagsmithClient/Classes/Feature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,21 @@ import Foundation
A Feature represents a flag or remote configuration value on the server.
*/
public struct Feature: Codable, Sendable {
enum CodingKeys: String, CodingKey {
case name
case type
case description
}

/// The name of the feature
public let name: String
public let type: String?
public let description: String?

init(name: String, type: String?, description: String?) {
self.name = name
self.type = type
self.description = description
}

public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.name, forKey: .name)
try container.encodeIfPresent(self.type, forKey: .type)
try container.encodeIfPresent(self.description, forKey: .description)
}
enum CodingKeys: String, CodingKey {
case name
case type
case description
}

/// The name of the feature
public let name: String
public let type: String?
public let description: String?

public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(name, forKey: .name)
try container.encodeIfPresent(type, forKey: .type)
try container.encodeIfPresent(description, forKey: .description)
}
}
Loading

0 comments on commit f0e9df2

Please sign in to comment.