views:

246

answers:

3

How come whenever i have to use awakeFromNib protocol, i have to put it in this format?

-(void)awakeFromNib

What is the need for -(void)?

Thanks,

FlaminLardMan

(p.s. im a noob at xcode and objective-c)

A: 

(void) marks the return type - in this case, void means it's returning nothing.

If it was instead -(int)awakeFromNib, you'd be expected to return an integer. The meaning of the return value (if any) should be explained in the documentation.

Steven Schlansker
thanx for your help!
blargman
+1  A: 

Because the method does not return anything, and giving a void return type is how you declare that in C and Objective-C.

Chuck
thanx for your help
blargman
+8  A: 

The -(void) is used in the declaration of the method. Presumably, you are defining it for someone else to call, rather than calling it yourself.

The - sign indicates that the method is an instance method, as opposed to a class method. It requires an object to call it, and instance variables of the object are available to it inside its definition.

The (void) indicates the return type. This method doesn't return anything, so its result can't be assigned to anything.

UncleO