This is a question on how to code this efficiently with as little as code possible. It already works but I need to incoporate the paramenter numberOfShapes. That if 1 returns ■, if 2 ■■, if 3 ■■■ etc…
I could do some extra if statemets and extra return statements. If Square->if number = 1> return ■, if number >2 return ■■ etc.. But that is a whole lot of code for something very simple.
What is the best way of coding this with the least amount of code?
- (NSString *)getShape: (NSNumber *)shape numberOfShapes: (NSNumber *)number
{
if ([shape isEqualToNumber:[NSNumber numberWithInt:SQUARE]]) return @"■";
if ([shape isEqualToNumber:[NSNumber numberWithInt:CIRCLE]]) return @"●";
if ([shape isEqualToNumber:[NSNumber numberWithInt:TRIANGLE]]) return @"▲";
return @"?";
}
I don’t see the point of using
NSNumberobjects to pass parameters like this, as they can’t do anything that a simpleNSUIntegerorunsignedcan, and are more expensive to use.