#define kSelectedTabDefaultsKey @"Selected Tab"
It just tells the compiler that everywhere he sees kSelectedTabDefaultsKey , he should expand it to @"Selected Tab" .
So this is:
NSInteger selectedTab = [defaults integerForKey:kSelectedTabDefaultsKey];
Becomes as follows:
NSInteger selectedTab = [defaults integerForKey:@"Selected Tab"];
selectedTab will end up returning an integerForKey: after the default manager looks at the @"Selected Tab" key in the default database. Presumably, it will be 0 or 1, corresponding to two values ββin your enumeration.
Enumeration is not associated with the default key, but is convenience.
enum { kByName, kBySecretIdentity, };
This tells the compiler to replace 0 whenever kByName is encountered, and 1 for kBySecretIdentity. No more no less.
Thus, presumably, the value written to the database will be one of 0 or 1. The enumeration exists in such a way that in the code for clarity you can say "kByName" instead of 0. In the code you sent, no enumeration is mentioned, because the value from the default database is simply passed in to select the tab.
It would be wise to check the result from the default database. List the listing as:
enum { kByName, kBySecretIdentity, kByUnusedSentinal };
Then:
NSInteger selectedTab = [defaults integerForKey:kSelectedTabDefaultsKey]; if ((selectedTab < 0) || (selectedTab >= kByUnusedSentinal)) selectedTab = kByName;
That way, if God ever writes to the default database, your application will use the kByName tab by default.