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

EZFormRadioField.valueOrUnselectedAtIndex throws NSInvalidArgumentException #64

Open
orkenstein opened this issue Aug 12, 2014 · 1 comment

Comments

@orkenstein
Copy link

This part of code:

- (NSString *)valueOrUnselectedAtIndex:(NSUInteger)index
{
    NSString *value = nil;
    if (self.unselected) {
    if (index == 0) {
        value = self.unselected;
    }
    else {
        NSString *key = [self.orderedKeys objectAtIndex:index - 1];
        value = [self.choices valueForKey:key];
    }
    }
    else {
    NSString *key = [self.orderedKeys objectAtIndex:index];
    value = [self.choices valueForKey:key];
    }
    return value;
}

... should use -(id)objectForKey instead of -(id)valueForKey.
Otherwise, if u use for example NSNumber as keys, u get:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
 reason: '-[__NSCFNumber length]: unrecognized selector sent to instance
@orkenstein orkenstein changed the title EZFormRadioField: - (NSString *)valueOrUnselectedAtIndex throws NSInvalidArgumentException EZFormRadioField.valueOrUnselectedAtIndex throws NSInvalidArgumentException Aug 12, 2014
@jessedc
Copy link
Contributor

jessedc commented Aug 17, 2014

Using valueForKey: with NSDictionary requires a string parameter as per the NSDictionary docs:

"Note that when using key-value coding, the key must be a string."

The EZForm code you've highlighted is also explicitly using NSStrings when fetching the key from orderedKeys which is correct use of the API.

NSDictionary also defers to objectForKey: in most uses of valueForKey:

Discussion
If key does not start with “@”, invokes objectForKey:. If key does start with “@”, strips the “@” and invokes [super valueForKey:] with the rest of the key.

I'm in two minds about whether or not this is an issue. I can't see a lot of use cases for NSNumber keys in a form, but having said that you could easily rewrite that method to read self.choices[key] and it probably wouldn't cause any harm.

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

2 participants