Take the 2-minute tour ×

I found some sample code from here.

static UIImage *backgroundImageDepressed;

@implementation DecimalPointButton

+ (void) initialize {
    backgroundImageDepressed = [[UIImage imageNamed:@"decimalKeyDownBackground.png"] retain];

is it something like this - +(void) initialize method initialize static variables of a class ( interface ) in objective c ? I have never seen this before.

Please need your guidance on it.

Thanks in advance for sharing your great knowledge.


share|improve this question
add comment

1 Answer

up vote 14 down vote accepted

This +initialize method is described in The Objective-C Programming Language.

The runtime system sends an initialize message to every class object before the class receives any other messages and after its superclass has received the initialize message. This gives the class a chance to set up its runtime environment before it’s used. If no initialization is required, you don’t need to write an initialize method to respond to the message.

For example, when [DecimalPointButton alloc] is called, the runtime will check if [DecimalPointButton initialize] has been called. If not, it will +initialize the class. This ensure the backgroundImageDepressed image is ready before any instances of DecimalPointButton are constructed.

share|improve this answer
add comment

Your Answer


