开发者

Correct Form for naming method parameters that clash with property names

开发者 https://www.devze.com 2023-04-05 13:57 出处:网络
If I have a class with a property of notificationCenter, and implement a method with this signature: -(void)doSomethingWithNotificationCenter:(NSNotificationCenter *)notificationCenter

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

精彩评论

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

关注公众号