Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

keyPathsForValuesAffectingValueForKey code should have 'else' statements #98

Closed
seanm opened this Issue · 2 comments

3 participants

@seanm

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

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

smic, of course! good idea!

wolf, would you accept such a patch?

@seanm seanm referenced this issue from a commit in seanm/mogenerator
@seanm seanm fixed issue #98, added early return in keyPathsForValuesAffectingValu…
…eForKey
646ae57
@seanm seanm referenced this issue
Merged

fixed issue #98 #108

@rentzsch rentzsch closed this
@ddrccw ddrccw referenced this issue from a commit in ddrccw/mogenerator
@seanm seanm fixed issue #98, added early return in keyPathsForValuesAffectingValu…
…eForKey
08710f2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.