Good practice for disambiguating argument names versus instance variable names in Objective-C

前端 未结 3 1813
花落未央
花落未央 2021-01-13 00:57

I run into a fairly common scenario in Objective-C where I pass in a variable to an init method and then want to assign it to an instance variable of the same name. However

3条回答
  •  渐次进展
    2021-01-13 01:21

    For setters (and by extension initializers), I believe the convention is to prefix the parameter name with new:

    - (void)setCrunk:(Crunk *)newCrunk;
    - (id)initWithCrunk:(Crunk *)newCrunk;
    

    In general, I think the most common form I've seen is to call the parameter theCrunk, but Apple seems to recommend aCrunk.

提交回复
热议问题