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

Support for objects? #2

Closed
scarlac opened this issue Feb 25, 2021 · 4 comments
Closed

Support for objects? #2

scarlac opened this issue Feb 25, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@scarlac
Copy link

scarlac commented Feb 25, 2021

Feature request:
I see references to things like convertObjCObjectToJSIValue and the reverse but mmkv.mm doesn't seem to be exposing this functionality.

Would it be possible to get native object/dict support so one could avoid using JSON.stringify() (and rely on the native counter-part)? Or have you found that it's more trouble than it's worth?

@mrousavy
Copy link
Owner

Hmm, on iOS there is support for storing id (basically any), I'll have to see how that will work.

What do you think the return type should be?

I'm thinking unknown:

getObject: (key: string) => unknown

@mrousavy mrousavy added the enhancement New feature or request label Feb 25, 2021
@mrousavy
Copy link
Owner

I'll see what's possible in #7

@samuel-rl
Copy link

A way to do it is already explain on documentation :

const user = {
  username: 'Marc',
  age: 21
}

storage.set('user', JSON.stringify(user))

const jsonUser = storage.getString('user') // { 'username': 'Marc', 'age': 21 }
const userObject = JSON.parse(jsonUser)

May this Issues should be closed ?

@mrousavy
Copy link
Owner

Yeah I think closing this issue makes sense. JSON is fast and easy, otherwise I would have to create a custom implementation and binary serializer (protobuf/flatbuf/flexbuf?) and that's maintainable native code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants