Tencent / MMKV

An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.
Other
17.1k stars 1.88k forks source link

鸿蒙里只有number类型,mmkv里区分了int32,int64 ,double, float等类型,请问在鸿蒙里mmkv里该如何使用 #1320

Closed ivluowei closed 1 month ago

ivluowei commented 1 month ago

鸿蒙里只有number类型,mmkv里区分了int32,int64 ,double, float等类型,请问在鸿蒙里mmkv里该如何使用

lingol commented 1 month ago

You can use them when:

  1. You have files encoded in Android or any other OS and migrated to OHOS.
  2. Or the number you are about to process is confirmed to be in the type/range of int32/int64/float/double etc.

It would help if you were as specific as possible. It's more efficient.

mistletoe5215 commented 1 month ago

我也遇到这个问题了,业务保存时间戳的场景取出来的值和存入的是会不一样的,方便起见用encodeDouble比较保险(js里number是64位的

 putSync<T>(spName: string, key: string, value: T): void {
    let mmkv = this.getPreference(spName)
    switch (typeof value) {
      case 'string':
        mmkv.encodeString(key, value)
        break;
      case 'number':
        mmkv.encodeDouble(key, value)
        break;
      case 'boolean':
        mmkv.encodeBool(key, value)
        break;
     ....
    }

  }