AppDelegate.h errors - XCode

2019-09-21 05:56发布

问题:

This is really weird. When coming back from school today and firing up my Mac Mini, I open up Xcode and I am presented with two errors in my AppDelegate.h file. One of these errors says Expected selector for Objective-C method and the other one is Expected method body. I googled these two errors and found nothing that could solve my case. I have tried restarting Xcode and as well as my computer. I have also tried "Cleaning" the project and still my problem is not resolved. What could this error be? Is it on my end? Or is this an Xcode bug? Thanks:

Code: AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window; 

@property (strong, nonatomic) UINavigationController *navigationController;

@end

回答1:

Check Your main.m File for any extra or invisible Code:

//
//  main.m
//  Demo
//
//  Created by Stackoverflow on 12/20/12.
//
//

#import <UIKit/UIKit.h>

#import "AppDelegate.h" 

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}


回答2:

What's in the corresponding .m file?

Are you @synthesizing accessors for your two properties? Failing to provide accessors (either synthesizing them or providing your own) seems like the most likely cause of the errors you've shown.

Have you implemented the usual app delegate methods? Off the top of my head, I'm not sure which if any app delegate methods are actually required, but your app isn't going to work very well and will produce some warnings if you don't have at least a -applicationDidFinishLaunching:withOptions:.



回答3:

With Xcode newer than 5.0, Anyone confronting this issue can from the top menu\Product\Build. It should resume right in the spot.