开发者

Correct Form for naming method parameters that clash with property names

If I have a class with a property of notificationCenter, and implement a method with this signature:

-(void)doSomethingWithNotificationCenter:(NSNotificationCenter *)notificationCenter

Xcode rightly gives me an error:

'local declaration of notificationCenter hides instance variable'

So in Objective C is there a c开发者_JAVA百科onvention for naming this parameter to avoid this collision?


The parameter should be called aNotificationCenter or possibly aCenter.


This seems like a personal preference, I have seen aNotificationCenter as mentioned above, inNotificationCenter, theNotificationCenter among others. I think as long as you are consistent in your own code any basic, readable choice is OK.

PS - my personal preference is inNotificationCenter.


I sometimes use the format receivedNotificationCenter or notificationCenterParam.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜