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.
精彩评论