ios轻松访问应用级属性

时间:2012-02-06 19:45:09

标签: ios

我在AppDelegate有一个属性,我想轻松抓住。到目前为止,它并没有按计划为我工作:

[(AppDelegate *)[UIApplication sharedApplication] wasLoggedIn] = YES

AppDelegate.h

@property (nonatomic, assign) BOOL wasLoggedIn;

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    wasLoggedIn = false;
}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

[(AppDelegate *)[UIApplication sharedApplication] wasLoggedIn] = YES;

应该是

[(AppDelegate *)[[UIApplication sharedApplication] delegate] wasLoggedIn] = YES;

您此刻正在调用UIApplication实例上的方法。