Q:

Xcode confusion - property and synthesize, retain?

I see the property and synthesize being used without "declaring the variable" first.. and I'm a bit confused about what properties to use. I want to alloc and init my viewController in AppDelegate and then be sure it's there for the remainder of the run. Clearly I want retain-property?..
however.. since alloc returns the viewController with retain count 1, it seams a lot smarter to just use leave the retain-property out. No other class will use my setter, so I don't care then?
Ex.
in AppDelegate.h:
    @propert(nonatomic,retain) MyViewController *myViewController;

in AppDelegate.m:
    @synthesize myViewController = _myViewController;
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.myViewController = [[[EventDataController alloc] init] autorelease];
        [self.window makeKeyAndVisible];
        return YES;
    }

or..
in AppDelegate.h:
    @propert(nonatomic) MyViewController *myViewController;

in AppDelegate.m:
    @synthesize myViewController = _myViewController;
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.myViewController = [[EventDataController alloc] init];
        [self.window makeKeyAndVisible];
        return YES;
    }

Set me straight, please.

A:

You don't need to define instance variables for properties anymore - @synthesize does that for you.
As for your other question - you can do it either way, but don't forget to release it in your -dealloc. I like (nonatomic, retain), because it is very clear and easy to use/understand. All you do is assign and it does all the rest:
self.myViewController = [[[ViewController alloc] init] autorelease];

In your -dealloc:
self.myViewController = nil;

In the case of manually releasing you might want to forget about properties at all and only use instance variables like this:
@interface MyClass: NSObject
{
  ViewController* _myViewController;
}
@end

In your implementation:
_myViewController = [[ViewController alloc] init];

In your -dealloc:
[_myViewController release];
_myViewController = nil;

Note that the last assignment of nil might be unnecessary, but I've had too many hard-to-track bugs with this (and that's why I love retained properties - all you need to do is set them to nil).
I try to always go with retained properties as this saves me some brain cycles and I don't care about the nanosecond I could save for the CPU otherwise.

