【发布时间】:2011-11-29 07:46:45
【问题描述】:
我在没有先“声明变量”的情况下看到使用了属性和合成。我对使用哪些属性有点困惑。我想在 AppDelegate 中分配和初始化我的 viewController,然后确保它在剩余的运行中存在。显然我想要保留属性? 但是.. 由于 alloc 返回保留计数为 1 的 viewController,因此仅使用保留属性会更智能。没有其他班级会使用我的 setter,所以我不在乎?
例如
在 AppDelegate.h 中:
@propert(nonatomic,retain) MyViewController *myViewController;
在 AppDelegate.m 中:
@synthesize myViewController = _myViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.myViewController = [[[EventDataController alloc] init] autorelease];
[self.window makeKeyAndVisible];
return YES;
}
或者..
在 AppDelegate.h 中:
@propert(nonatomic) MyViewController *myViewController;
在 AppDelegate.m 中:
@synthesize myViewController = _myViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.myViewController = [[EventDataController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}
请让我直截了当。
【问题讨论】:
标签: iphone xcode properties retain init