开发者

Is it OK to use "id" as a property name?

I created an object with an "id" property (it's coming from a database with uniqu开发者_开发问答e ids). Then I remembered that "id" is a class name in Cocoa. There didn't seem to be any issue with using an int property named "id", but will I run into problems later?


You can use id as a property name since typedefs and declared properties are in separate name spaces.

That said, you should consider using a more descriptive property name, particularly one that is more robust against conflict with method names. There are situations where methods with same names but different return types can cause problems, e.g. dynamic typing.

Also, using a more descriptive name is especially important when using Core Data because a Core Data property name cannot have the same name as a method name in NSObject or NSManagedObject with no parameters.


In my practice, I always name id as identifier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜