joec
joec

Reputation: 3543

Method not found in protocol: Objective C

I have this in my view controller:

[[[UIApplication sharedApplication] delegate] sendMessageAsSingleObject:[sender currentTitle]];

Which gives me this warning:

warning: '-sendMessageAsSingleObject:' not found in protocol(s)

But in my AppDelegate i have the method declared in the header...

I should add that the call works, just want to get rid of the warnings.

Thanks

Upvotes: 1

Views: 1401

Answers (1)

V1ru8
V1ru8

Reputation: 6147

[[UIApplication sharedApplication] delegate]

Returns an object that implements the UIApplicationDelegate protocol. This protocol doesn't have the method sendMessageAsSingleObject. So your compiler doesn't know that this method is actually there. You need to cast the delegate first to the specific class of your application delegate.

MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate sendMessageAsSingleObject:[sender currentTitle]];

Upvotes: 5

Related Questions