Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is your alternative name for ID variable in Objective-C?

Since "id" is a keyword in Objective-C what alternative name do you use for ID variable (e.g. PK field)?

like image 492
osxdev12 Avatar asked Feb 29 '12 19:02

osxdev12


People also ask

What is id type in Objective-C?

“id” is a data type of object identifiers in Objective-C, which can be use for an object of any type no matter what class does it have. “id” is the final supertype of all objects.

What does #id mean in C?

id is a generic type. This means that the compiler will expect any object type there, and will not enforce restrictions. It can be useful if you're expecting to use more than one class of objects there; you can then use introspection to find out which class it is.

What is a correct variable name?

Rules for naming a variableA variable name can only have letters (both uppercase and lowercase letters), digits and underscore. The first letter of a variable should be either a letter or an underscore. There is no rule on how long a variable name (identifier) can be.


1 Answers

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.

like image 68
jscs Avatar answered Oct 12 '22 01:10

jscs