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

keyPathsForValuesAffectingValueForKey code should have 'else' statements #98

Closed
seanm opened this issue Mar 23, 2012 · 2 comments
Closed

Comments

@seanm
Copy link
Contributor

seanm commented Mar 23, 2012

The code generated for the keyPathsForValuesAffectingValueForKey method ends up like this:

  • (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
    NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];

    if ([key isEqualToString:@"angleXValue"]) {
    NSSet *affectingKey = [NSSet setWithObject:@"angleX"];
    keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKey];
    }
    if ([key isEqualToString:@"angleYValue"]) {
    NSSet *affectingKey = [NSSet setWithObject:@"angleY"];
    keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKey];
    }

    return keyPaths;
    }

Which is fine, but since we're always comparing the same 'key' and we never want to enter more than one 'if', it would be better that we had 'else' statements after the first 'if'.

It could give a small performance boost too, or certainly be no worse.

@smic
Copy link
Contributor

smic commented Apr 20, 2012

You could also simply return in the if clause. It might be simpler to create a template.

if ([key isEqualToString:@"angleXValue"]) {
NSSet *affectingKey = [NSSet setWithObject:@"angleX"];
return [keyPaths setByAddingObjectsFromSet:affectingKey];
}

@seanm
Copy link
Contributor Author

seanm commented Apr 20, 2012

smic, of course! good idea!

wolf, would you accept such a patch?

seanm added a commit to seanm/mogenerator that referenced this issue Apr 24, 2012
@seanm seanm mentioned this issue Apr 24, 2012
rentzsch added a commit that referenced this issue May 10, 2012
ddrccw pushed a commit to ddrccw/mogenerator that referenced this issue Jan 20, 2014
ddrccw pushed a commit to ddrccw/mogenerator that referenced this issue Jan 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants