Skip to content

Instantly share code, notes, and snippets.

View juliuscanute's full-sized avatar
💭
I may be slow to respond.

juliuscanute

💭
I may be slow to respond.
View GitHub Profile
@juliuscanute
juliuscanute / iOSConfigureSmall.swift
Created May 30, 2020 03:13
Configure Small Swift
appConfig {
$0.config(environment: "FREE") {/*...*/}
$0.config(environment: "PREMIUM") {/*...*/}
}
@juliuscanute
juliuscanute / iOSConfigure.swift
Last active May 30, 2020 08:27
iOS Configuration
appConfig {
$0.config(environment: "FREE") {
$0.switch {
$0.key = "A"
$0.description = "Set text visibility"
$0.switchValue = true
}
$0.range {
$0.key = "B"
$0.description = "Set text size"
@juliuscanute
juliuscanute / AndroidConfigure.kt
Last active May 30, 2020 08:25
Configure Android
appConfig {
config("FREE") {/*...*/}
config("PREMIUM") {
switch {
key = "A"
description = "Set text visibility"
switchValue = false
}
range {
@juliuscanute
juliuscanute / Podfile
Created May 30, 2020 02:47
iOS Podfile
# Podfile
use_frameworks!
target 'YOUR_TARGET_NAME' do
pod 'MultiConfig', '~> 1.0.59'
end
@juliuscanute
juliuscanute / build.groovy
Created May 30, 2020 02:43
Gradle Dependency
implementation('com.juliuscanute.multiconfig:multiconfig:1.0.59@aar') {
transitive = true
}
@juliuscanute
juliuscanute / IOSImplementation.kt
Created May 28, 2020 11:04
iOS Implementation
actual class Settings(group: String) {
private val defaults = NSUserDefaults(suiteName = group)
/*..*/
actual fun getInt(key: String, defaultValue: Int): Int {
val value = defaults.integerForKey(defaultName = key)
return value.toInt()
}
/*..*/
actual fun putInt(key: String, value: Int) {
defaults.setInteger(value = value.toLong(), forKey = key)
actual class Settings(context: Context, name: String = "multi-config") {
private var sharedPreference: SharedPreferences = context.getSharedPreferences(name, MODE_PRIVATE)
/*..*/
actual fun getInt(key: String, defaultValue: Int): Int =
sharedPreference.getInt(key, defaultValue)
/*..*/
actual fun putInt(key: String, value: Int) {
sharedPreference.edit()
.putInt(key, value)
.apply()
@juliuscanute
juliuscanute / Settings.kt
Created May 28, 2020 10:50
Setting Expectations
expect class Settings {
/*..*/
fun getInt(key: String, defaultValue: Int): Int
/*..*/
fun putInt(key: String, value: Int)
/*..*/
}
@juliuscanute
juliuscanute / ConfigurationRepository.kt
Created May 28, 2020 10:42
Configuration Repository
/*..*/
fun saveConfig(key: String, value: Int) {
val userKey = getUserKey(key)
store[userKey] = StoreValue.IntValue(value = value)
settings.putInt(userKey, value)
}
/*..*/
/*..*/
override fun getConfigInt(userKey: String): Int {
val key = environment + PREFIX + userKey
val storeValue: StoreValue? = store[key]
checkNotNull(storeValue, { "Unable to find the key" })
check(storeValue is StoreValue.IntValue) { "Store value must be Int" }
return storeValue.value
}
/*..*/