Since "id" is a keyword in Objective-C what alternative name do you use for ID variable (e.g. PK field)?
由于“id”是Objective-C中的关键字,您对ID变量使用什么替代名称(例如PK字段)?
6 个解决方案
#1
18
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,
我认为应该注意,编译器可以区分类型说明符位置中的id和变量名称位置中的id。那是,
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.
将编译得很好(实际上,将id id; id = [NSNumber numberWithInt:10];)。 (你也可以大写它:ID。)那就是说,这些都是可怕的想法。不要使用它们。忘了我甚至说过。
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
.
Cocoa编程中的风格倾向于冗长,因此(正如所有早期的答案所暗示的那样)最佳实践可能是全部写出来:标识符或dinglehopferID。
#2
3
identifier
, or something more specific like userID
.
标识符,或更具体的内容,如userID。
#3
0
It often depends on context. Simply, identifier
if I'm not feeling particularly creative.
它通常取决于背景。简单地说,标识符,如果我感觉不是特别有创意。
#4
0
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'.
我倾向于使用“标识符” - 如果真的没有更好的替代方案 - 或某些特定于域名的“programmeID”,它们会说'这是主键,但仅限于此域'。
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.
实际上很少有人必须考虑Cocoa中的主键。 Core Data保留了没有任何主键提名的对象图,NSPredicates不会给每个对象恰好是唯一的字段赋予任何额外的权重,并且NSDictionarys倾向于以一种特殊的方式构建。
#5
0
I almost use 'guid' NSString *guid
NSNumber *guid
.
我几乎使用'guid'NSString * guid NSNumber * guid。
http://en.wikipedia.org/wiki/Globally_unique_identifier
http://en.wikipedia.org/wiki/Globally_unique_identifier
#6
0
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.
使用id对我来说是一个坏主意。我几乎分别对用户和客户使用'uid'或'cid'。我使用模型名称的第一个字母来避免保留字。
#1
18
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,
我认为应该注意,编译器可以区分类型说明符位置中的id和变量名称位置中的id。那是,
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.
将编译得很好(实际上,将id id; id = [NSNumber numberWithInt:10];)。 (你也可以大写它:ID。)那就是说,这些都是可怕的想法。不要使用它们。忘了我甚至说过。
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
.
Cocoa编程中的风格倾向于冗长,因此(正如所有早期的答案所暗示的那样)最佳实践可能是全部写出来:标识符或dinglehopferID。
#2
3
identifier
, or something more specific like userID
.
标识符,或更具体的内容,如userID。
#3
0
It often depends on context. Simply, identifier
if I'm not feeling particularly creative.
它通常取决于背景。简单地说,标识符,如果我感觉不是特别有创意。
#4
0
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'.
我倾向于使用“标识符” - 如果真的没有更好的替代方案 - 或某些特定于域名的“programmeID”,它们会说'这是主键,但仅限于此域'。
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.
实际上很少有人必须考虑Cocoa中的主键。 Core Data保留了没有任何主键提名的对象图,NSPredicates不会给每个对象恰好是唯一的字段赋予任何额外的权重,并且NSDictionarys倾向于以一种特殊的方式构建。
#5
0
I almost use 'guid' NSString *guid
NSNumber *guid
.
我几乎使用'guid'NSString * guid NSNumber * guid。
http://en.wikipedia.org/wiki/Globally_unique_identifier
http://en.wikipedia.org/wiki/Globally_unique_identifier
#6
0
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.
使用id对我来说是一个坏主意。我几乎分别对用户和客户使用'uid'或'cid'。我使用模型名称的第一个字母来避免保留字。