Code Monkey home page Code Monkey logo

mmkv's Introduction

mmkv

使用 kotlin 委托属性封装的 mmkv 库,代替 SharedPreferences,简单好用

  • 支持基本类型:int/long/float/double/boolean
  • 支持对象类型:字符串,字符串集合,字节数组
  • 支持可空对象类型:字符串,字符串集合,字节数组
  • 支持Parcelable类型

引入

repositories {
    maven { url "https://gitee.com/ezy/repo/raw/cosmo/"}
}
dependencies {
    implementation "me.reezy.cosmo:mmkv:0.7.0"
}

使用

委托属性添加在实现了 MMKVOwner 的类上,委托属性的值存储在从 MMKVOwner 获取的 MMKV 实例中

否则存储在默认的 MMKV 实例中

class SomeActivity : Activity {

    // 委托属性的值存储在默认的 MMKV 实例中
    private var isFirstLaunch by mmkvBoolean(default = true)


    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)

        // 赋值
        isFirstLaunch = false

        // 判断
        if (isFirstLaunch) {
            // todo
        }
    }
}
object SomeManager {
    private object store : MMKVOwner {
        // store 对象的委托属性的值存储此 MMKV 实例中
        override val mmkv: MMKV = MMKV.mmkvWithID("some")

        var intValue by mmkvInt()
        var longValue by mmkvLong()
        var floatValue by mmkvFloat(0f)
        var booleanValue by mmkvBoolean(false)
        var stringValue by mmkvString("some")
        var nullableStringValue by mmkvNullableString()
    }
}

LICENSE

The Component is open-sourced software licensed under the Apache license.

mmkv's People

Contributors

czy1121 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.