Reputation: 163
Since "id" is a keyword in Objective-C what alternative name do you use for ID variable (e.g. PK field)?
Upvotes: 14
Views: 4219
Reputation: 1305
Using id is a bad idea for me. I almost use 'uid' or 'cid' for Users and Clients respectively. I use the first letter of the model name to avoid the reserved word.
Upvotes: 0
Reputation: 2535
I almost use 'guid' NSString *guid
NSNumber *guid
.
http://en.wikipedia.org/wiki/Globally_unique_identifier
Upvotes: 0
Reputation: 64002
I think it should be noted that the compiler can distinguish between id
in the type specifier position and id
in the variable name position. That is,
NSUInteger id;
id = 10;
will compile just fine (as, indeed, will id id; id = [NSNumber numberWithInt:10];
). (You could also uppercase it: ID
.) That said, those are all horrible ideas. Don't use them. Forget I even said that.
The style in Cocoa programming is to tend towards verbosity, so (as all the earlier answers have suggested) the best practice is probably to write it all out: identifier
or dinglehopferID
.
Upvotes: 18
Reputation: 100622
I tend to use either 'identifier' — if there's really no better alternative — or something domain specific like 'programmeID' which sort of says 'this is the primary key, but only with respect to this domain'.
It's actually quite rare that you have to think in terms of primary keys within Cocoa. Core Data preserves object graphs without any nomination of primary keys, NSPredicate
s don't give inherently any additional weight to a field that happens to be unique per object and NSDictionary
s tend to be built in an adhoc fashion.
Upvotes: 0
Reputation: 104698
It often depends on context. Simply, identifier
if I'm not feeling particularly creative.
Upvotes: 0