Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why not support NSDictionary as NSUserDefault #10

Closed
yuman07 opened this issue Sep 21, 2018 · 10 comments
Closed

why not support NSDictionary as NSUserDefault #10

yuman07 opened this issue Sep 21, 2018 · 10 comments

Comments

@yuman07
Copy link

yuman07 commented Sep 21, 2018

The language of MMKV

Objective-C

The version of MMKV

v1.0.10

The platform of MMKV

iOS

The installation of MMKV

Cocoapods

What's the issue?

For me, I often use a NSUserDefault to do some simple data persistence. And the NSDictionary is a very important one. Why is there no support for it?

@lingol
Copy link
Collaborator

lingol commented Sep 21, 2018

Mainly because NSDictionary's value type is uncertain, it's hard to encode/decode NSDictionary properly in protobuf, if not possible.

However, you can turn a NSDictionary into a NSData by NSArchive, and store that NSData in MMKV.

@MichaelJokAr
Copy link

+1

@yuman07
Copy link
Author

yuman07 commented Sep 21, 2018

NSUserDefault can read/write NSDictionary directly, and MMKV needs to do a conversion through NSArchive. If you consider the consumption of conversion, is the performance advantage of MMKV still greater than NSUserDefault?

@lingol
Copy link
Collaborator

lingol commented Sep 21, 2018

NSUserDefault can read/write NSDictionary directly, and MMKV needs to do a conversion through NSArchive. If you consider the consumption of conversion, is the performance advantage of MMKV still greater than NSUserDefault?

Well, NSUserDefault's NSDictionary support doesn't come in free. Which algorithm do you think it used to store NSDictionary? NSArchive? I haven't test it yet, but that's my best guess.

Given that guess, I have confidence MMKV will beat NSUserDefault in such case.

@yuman07
Copy link
Author

yuman07 commented Sep 21, 2018

thx~

@wg689
Copy link

wg689 commented Sep 25, 2018

you tell me I should better convert dictionary or Nsarray to NSData ,not the jsonStr , the reason is ( value type is uncertain, it's hard to encode/decode NSDictionary properly)? when I conert to jsonStr , all is NSString ,
or have other reason ?

@lingol
Copy link
Collaborator

lingol commented Sep 26, 2018

you tell me I should better convert dictionary or Nsarray to NSData ,not the jsonStr , the reason is ( value type is uncertain, it's hard to encode/decode NSDictionary properly)? when I conert to jsonStr , all is NSString ,
or have other reason ?

Use NSData for efficiency, or JSON for convenience. It's your choice.

@Damonvvong
Copy link
Contributor

其实可以提供一个直接存 NSDictionary 的 api。然后内部进行一步转换~你觉得呢?

@lingol

@lingol
Copy link
Collaborator

lingol commented Sep 26, 2018

其实可以提供一个直接存 NSDictionary 的 api。然后内部进行一步转换~你觉得呢?

@lingol

Maybe.

This was referenced Sep 27, 2018
@lingol
Copy link
Collaborator

lingol commented Oct 9, 2018

Supported with #78 , checkout release note.

@billdizl billdizl mentioned this issue Apr 28, 2022
Closed
This was referenced Oct 25, 2023
@beefeng beefeng mentioned this issue Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants