user370507
user370507

Reputation: 497

Calling Method in xCode

When calling a method, I use

[self methodname];

The problem I'm having is, in xCode I get loads of warnings! It's saying "*xxxappdelegate.app may not respond to methodname*".

Is there a better way to call methods?

Upvotes: 5

Views: 28509

Answers (5)

amar
amar

Reputation: 4345

If the .h file has the method declared there can be some issue related to xcodes inability to index to solve this go to preferences and delete archives and other stored data.

Upvotes: 0

Mustafa
Mustafa

Reputation: 11

There is something called compiling order. When you call method foo it is not defined yet, however when you call method blah it is defined just in the upper line.

Much more specific:

cout << a;
string a = "hello";

When you do that you will get an error undefined variable "a". What you should do is:

string a = "hello";
cout << a;

Upvotes: 1

drawnonward
drawnonward

Reputation: 53659

Add methodname to the @interface for the class, xxxappdelegate in your example. Or just make sure the methodname implementation is before the place you call it in the file.

Upvotes: 0

Gary
Gary

Reputation: 5732

These warnings just mean that the compiler does not know if the class in question has the method you are calling. Make sure the method you're calling is defined above the place in the .m file you are using it in, or declare the method at the top of the file.

@implemention A

-(void)blah
{
    [self foo]; // warning!
}

-(void)foo
{
    [self blah]; // no warning
}

@end

Upvotes: 4

indragie
indragie

Reputation: 18122

If you get that warning, that means either:

  • That method does not exist in your class
  • If you are calling that method on a different class (not self) then you have not imported the headers for that class

Upvotes: 5

Related Questions