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

前端 未结 3 1816
花落未央
花落未央 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:29

    And changing the name to "inValue" is not a good idea? What you have here - your 'solution' is complex, especially with the accessors, etc of Obj-C 2. Since self.value and inValue are different things, they need different names.

    Note that you can use

    -(void)method1:(NSString*)value; 
    

    in the header

    and

    -(void)method1:(NSString*)inValue; 
    

    in the .m file.

提交回复
热议问题