Simplify your code using Dictionaries
Published by Marian on Tuesday, November 11, 2008 7:12 PM
Too complicated conditions?
or
Keep it simple!
and
Source
if ([[self stateName] isEqual:@"Square"])
{
if (self.clockwise)
{
return @"Animating around four points, clockwise";
}
else
{
return @"Animating around four points, anti-clockwise";
}
}
else if ([[self stateName] isEqual:@"Triangle"])
{
if (self.clockwise)
{
return @"Animating around three points, clockwise";
}
else
{
return @"Animating around three points, anti-clockwise";
}
}
or
if ([[stateController stateName] isEqual:@"Square"])
{
[path fill];
}
else if ([[stateController stateName] isEqual:@"Triangle"])
{
[path stroke];
}
Keep it simple!
return [self.selectedItem objectForKey:[self clockwiseKey]];
and
SEL drawSelector = NSSelectorFromString(
[stateController.selectedItem objectForKey:@"drawSelector"]);
[path performSelector:drawSelector withObject:nil];
Source