8

Declaring, implementing and using method like this:

Test.h:

- method:parameter; 

Test.m:

- method:parameter{ return nil; } 

Using:

[test method:anObject]; 

There is no return-type and parameter-type, but it works without any warning or error. Can somebody explain it?

2
  • The return type is void the return value is nil ! Commented Jun 9, 2011 at 6:11
  • 1
    @ViTo Brothers Apoyan, actually no, it's id if it's unspecified. Commented Jun 9, 2011 at 6:23

3 Answers 3

12

As the Objective-C Programming Language document states:

If a return or parameter type isn’t explicitly declared, it’s assumed to be the default type for methods and messages — an id.

So:

- method:parameter; 

effectively means:

- (id)method:(id)parameter; 

and, correspondingly:

- method:parameter{ return nil; } 

effectively means:

- (id)method:(id)parameter{ return nil; } 
Sign up to request clarification or add additional context in comments.

Comments

4

From The Objective-C Programming Language:

If a return or parameter type isn’t explicitly declared, it’s assumed to be the default type for methods and messages—an id.

Comments

3

Default type in Obj-C is id. So here the both the return and parameter is id.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.