rentzsch / mogenerator

Core Data code generation

Home Page:http://rentzsch.github.com/mogenerator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

keyPathsForValuesAffectingValueForKey code should have 'else' statements

seanm opened this issue · comments

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.

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];
}

smic, of course! good idea!

wolf, would you accept such a patch?