Tencent / MMKV

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

encode with null value == remove key ??? #1323

Closed jqctop1 closed 4 months ago

jqctop1 commented 4 months ago

Note:

An crash issue will be ignored & closed in a week without logs.

The language of MMKV

Kotlin

The version of MMKV

1.3.4 Note: For versions older than the latest version, please upgrade before posting any issue.
We don't have much time for old version tech support.

The platform of MMKV

Android

What is the issue?

mmkv.encodeString(key, null) mmkv.containsKey(key) 会返回false 这个api设计的合理吗?有多少人知道encode一个null就等价于删掉key?

还有removeKey的默认实现就是removeValueForKey 。。。这样暴露两个接口的目的是什么?

lingol commented 4 months ago

It's a common practice whenever a null value is stored the key gets deleted.

lingol commented 4 months ago

As for the duplication of remove()& removeValueForKey(), MMKV originally provides removeValueForKey(). Later on, to make the migration from SharedPreferences to MMKV easy, MMKV implements the interface SharedPreferences.Editor which provides remove().

Now it is too late to remove either one of them. Sorry for any trouble or misunderstanding.