grossmae
grossmae

Reputation: 341

Why does xcode sometimes find instance methods not declared in header files?

Of course it is best practice to declare all methods in the header file, so I appreciate when xcode warns me than an instance method may not be found. However, there are cases when I have not declared a method in the header, and I do not get a warning. These are definitely not any delegate methods, so what other cases would cause this behavior?

Upvotes: 0

Views: 335

Answers (3)

DAS
DAS

Reputation: 1941

If you call your method under your method body definition it works, like:

-(void)foo { bla }
[self foo];

If you too the other way around it crashes (if the method it not in your header file):

[self foo];
-(void)foo { bla }

Upvotes: 1

Mike K
Mike K

Reputation: 2227

if your method is not declared in the header file (or a class extension), but comes before another method which is referencing it then you won't get an error.

Upvotes: 1

mattjgalloway
mattjgalloway

Reputation: 34912

Probably the method has already been defined in the implementation by the time it is used. i.e. if the method being used is above the place it's used in the implementation file then the compiler knows the method signature so all is OK.

Upvotes: 2

Related Questions