Since "id" is a keyword in Objective-C what alternative name do you use for ID variable (e.g. PK field)?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
- Why is my library not able to expand on the CocoaP
It often depends on context. Simply,
identifier
if I'm not feeling particularly creative.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 andNSDictionary
s tend to be built in an adhoc fashion.I think it should be noted that the compiler can distinguish between
id
in the type specifier position andid
in the variable name position. That is,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
ordinglehopferID
.identifier
, or something more specific likeuserID
.I almost use 'guid'
NSString *guid
NSNumber *guid
.http://en.wikipedia.org/wiki/Globally_unique_identifier
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.