I had my application working fine, then without doing anything, out of nowhere I got 2 errors in appDelegate.h
. One says this:
Expected selector for Objective-C method
The other says this:
Expected method body
I have no idea why this is happening, I have other projects with the exact same app delegate and they all work just fine.
This is my appDelegate.h:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate> // I get the errors here
@property (strong, nonatomic) UITabBarController *tbc;
@property(strong, nonatomic) UIWindow *window;
@end
I had the same problem. At last I found that in my main.m I had accidentally added a "-" character in the beginning of the file.
Removing the character solved the problem.
I usually find that a mysterious error like this happens because I accidentally typed a stray character into one of my other source files - either at the end of one of the other header files, or at the top of a .m
file.
Look at the top of the .m
file that Xcode is trying to compile. Check it for stray characters. If you don't find any, look at which file is imported just before AppDelegate.h
. Check for stray characters at the end of that other header file. If you have header files that import AppDelegate.h
, you may have to check those too. (There's really no reason any other .h
file should have to import AppDelegate.h
.)
Try closing Xcode and then reopening and doing a clean build.
If that doesn't fix it, it's possible you've got a circular reference in one of your header files.
This can happen when foo.h #imports "bar.h" and bar.h #imports "foo.h" (or sometimes its a chain of three or more header files importing each other in a circle) and it leads to spurious errors like the one you're seeing.
The solution is to try to avoid importing headers in your .h files, and instead use @class references for external classes in the .h files and put the #imports in the .m files instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With