1

Xcode 有关于Autosynthesized property 'ViewController'和相似的问题,'window'并告诉我属性是在 BSAppDelegate.h 中声明的。尽管这里有几个人试图解释下划线问题,但我不知道如何解决这个问题。当我省略下面提到 ViewController 或窗口的任何行时,我的应用程序将无法编译。

//
//  BSAppDelegate.h
//

#import <UIKit/UIKit.h>

@class BSViewController;

@interface BSAppDelegate : UIResponder <UIApplicationDelegate>{
    UIWindow *window;
    BSViewController *viewController;
}


@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) BSViewController *viewController;

@end
4

1 回答 1

1

当你声明属性时,你不需要在实例变量部分也声明相同的变量。换句话说,这应该没问题:

@interface BSAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) BSViewController *viewController;

@end

如果您的应用程序无法像这样编译,您是否有第二个@interface 部分和/或您在实现文件中是否有@synthesize 语句?从 Xcode 4.4 开始,您不再需要 @synthesize 语句,但如果您没有显式合成属性,那么 Xcode 将使用前面的下划线(_window 或 _viewController)合成它们。这是一个包含更多信息的链接:Automatic Property Synthesis With Xcode 4.4

于 2013-01-20T03:53:46.407 回答