tags:

views:

72

answers:

1

hi,the code is

 NSString *st = [[UIColor greenColor] description];

it gives wrong output. i want to get the Result , st must be @"greenColor" as a NSString any help please?

+3  A: 

greenColor is just the name of a class method on UIColor. Once the UIColor is constructed it doesn't know it's a greenColor - it just knows that it has colour values that happen to make green.

So I'd suggest one of two things.

  1. Create a category on UIColor that intercepts description and compares the colour values against the set of colour constructors and return the appropriate string.
  2. Subclass UIColor and store a colour name string. Supply a description method that just returns that string.

I suspect (2) is simpler but requires that you are able to use your subclassed version instead of UIColor.

Phil Nash