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

iosMain.com.softartdev.theme.pref.IosPreferenceHelper.kt Maven / Gradle / Ivy

Go to download

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

The newest version!
package com.softartdev.theme.pref

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