Rays of wisdom


Stickies for an ageing brain

Showing posts with label cocoa. Show all posts
Showing posts with label cocoa. Show all posts

Simplify your code using Dictionaries

Published by Marian on Tuesday, November 11, 2008 7:12 PM

Too complicated conditions?

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

 

Lipsum

Rays of wisdom
Notepad entries by Marian Mihailescu.

Followers