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

iOS & Objective-C no type detection for Key #15

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

iOS & Objective-C no type detection for Key #15

yuman07 opened this issue Sep 21, 2018 · 3 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?

I found that all set&get methods call 'key.length' for check key vaild, but the passed key will be crash if it is an id type but not a string.

@yuman07
Copy link
Author

yuman07 commented Sep 21, 2018

if (!key || ![key isKindOfClass:[NSString class]] || key.length == 0) {
    return;
}

I think this will be better!

@lingol
Copy link
Collaborator

lingol commented Sep 21, 2018

Well, the interface is
- (BOOL)setxxx forKey:(NSString *)key;
Notice the type of key is specify here, requiring NSString. Let your code-checking-tool do the job.

And one more thing, checking parameter's type is a little luxurious for a frequently called interface.

@rizwankce
Copy link

Agree with @lingol here.

interface is specifically mentioning the type of the parameter. To force the user not to send anything else we could use some assertions NSAssert with message. So developers will get error/warning when they run into issues of sending wrong type.

@lingol lingol closed this as completed Sep 26, 2018
@sven-brobonds sven-brobonds mentioned this issue Jul 21, 2020
@billdizl billdizl mentioned this issue Apr 28, 2022
Closed
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

3 participants