Skip to content

FRemocon can get the FirebaseRemoteConfig value type-safely

License

Notifications You must be signed in to change notification settings

funzin/FRemocon

Repository files navigation

FRemocon

GitHub Action Platform Language License License

DEMO

Environment

  • Xcode 12.4 or greater
  • Swift 5.3 or greator

Installation

Swift Package Manager

Add the following code in Package.swift.

dependencies: [
    .package(url: "https://github.com/funzin/FRemocon.git", from: "0.1.0"),
]

CocoaPods

Add the following code in Podfile.

pod 'FRemocon'

Usage

  1. Add the key set in Firebase RemoteConfig as ConfigKey
extension ConfigKeys {
    var text: ConfigKey<String> { .init(key: "text", defaultValue: "defaultValue") }
    var flag: ConfigKey<Bool> { .init(key: "flag", defaultValue: false) }
    var intNumber: ConfigKey<Int> { .init(key: "intNumber", defaultValue: 1) }
}
  1. The value will be accessible through ConfigKey
let remoteConfig = FRemocon.shared
remoteConfig.fetch() { (status, error) -> Void in
  if status == .success {
    print("Config fetched!")
    remoteConfig.activate() { (changed, error) in
      // Value obtained by RemoteConfig
      let text: String = remoteConfig.text
      print(text: \(text))
    }
  } else {
    print("Config not fetched")
    print("Error: \(error?.localizedDescription ?? "No error available.")")
  }
  self.displayWelcome()
}

Supported types

Currently support the following types

Name
Int
Float
Double
String
Coudable
RawRepresentable

Get/Set to RemoteConfig value

Can get / set the FirebaseRemoteConfig value by using Key Path Member Lookup.

Get

// before
let lastFetchStatus = RemoteConfig.remoteConfig().lastFetchStatus

// after
let lastFetchStatus = FRemocon.shared.lastFetchStatus

Set

// before
RemoteConfig.remoteConfig().configSettings = RemoteConfigSettings()

// after
FRemocon.shared.configSettings(RemoteConfigSettings())

GoogleService-Info

Use GoogleService-Info similar to mock-GoogleService-Info

Development

  1. git clone https://github.com/funzin/FRemocon
  2. open FRemocon.xcodeproj

Contact

If you discover problem or have some opinions, please let me know through Github issues💁‍♂️

Author

funzin

License

Rimuru is available under the MIT license. See the LICENSE file for more info.