Can't declare another window

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 04:36:40

问题


I'm trying to declare another window in MyThing.m

@property (nonatomic, strong) UIWindow *window;

But get this error

Illegal redeclaration of property in class extension "MyThing" (attribute must be 'readwrite', while its primary must be 'readonly')

If I rename window to something else, it is OK. Why is that? Is window meant to be declared once in the AppDelegate.h ?


回答1:


I figure out the problem, it has nothing to do with the window property declared in AppDelegate.h

The problem is MyThing conforms to UIApplicationDelegate, and UIApplicationDelegate protocol declare a property

@property (nonatomic, retain) UIWindow *window NS_AVAILABLE_IOS(5_0);

So we must do either of these

MyThing.h (like AppDelegate.h does)

@interface MyThing : NSObject <UIApplicationDelegate>

@property (nonatomic, strong) UIWindow *window;

@end

OR

MyThing.m (synthesize the window property declared in protocol)

@implementation WYNAppDelegate

@synthesize window;

@end


来源:https://stackoverflow.com/questions/24715715/cant-declare-another-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!