All Downloads are FREE. Search and download functionalities are using the official Maven repository.

iosMain.com.softartdev.themepref.IosPreferenceHelper.kt Maven / Gradle / Ivy

Go to download

Kotlin Multiplatform library for easy switching Dark/Light Material themes on Compose.

There is a newer version: 0.5.5
Show newest version
package com.softartdev.themepref

import androidx.compose.runtime.Composable
import platform.Foundation.NSUserDefaults

class IosPreferenceHelper : PreferenceHelper {

    private var preferences: NSUserDefaults = NSUserDefaults.standardUserDefaults

    override var themeEnum: ThemeEnum
        get() = preferences.integerForKey(defaultName = THEME_KEY).toInt().let(ThemeEnum.values()::get)
        set(value) = preferences.setInteger(value.ordinal.toLong(), THEME_KEY)

    override fun clear() = preferences.removeObjectForKey(defaultName = THEME_KEY)
}

@Composable
actual fun obtainPreferenceHelper(): PreferenceHelper = IosPreferenceHelper()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy