objective c - Is it OK to have a method's variable with the same name as a declared property? -


i understand bad practice, curious whether or not has negative side-effects, in objective-c (trying learn as can):

@interface myclass ()  // declare string called 'foo'  @property (nonatomic, strong) nsstring *foo  @end  @implementation myclass   ...  - (void)modifyfoo {      // create local variable same name property      nsstring *foo = @"hello!" // no compiler warnings?      self.foo = foo; // <---- ok?  } 

this not throw warning in compiler, , sure enough, code works normal. if there 0 negative side-effects, type of property, e.g. weak/strong/assign, etc, have influence on whether or not ok?

note: aware not work when property synthesised.

this fine , preferred approach. reason no compiler warning generated instance variable named _foo. done auto-synthesise added compiler (it generates @synthesize foo = _foo you). maintaining naming consistency aids clarity.

the main potential side effect inadvertently add / fail add self. , end trying message nil.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -