objective c - @property vs just declaring getter and setter -


is there difference in behaviour - either @ compile time or @ run time - between code...

// myclass.h @interface myclass : nsobject  @property (nonatomic) sometype myproperty;  @end  // myclass.m @implementation myclass  @end 

... , code?

// myclass.h @interface myclass : nsobject  -(sometype)myproperty; -(void)setmyproperty:(sometype)myproperty;  @end  // myclass.m @implementation myclass {     sometype _myproperty; }  -(sometype)myproperty {     return _myproperty; }  -(void)setmyproperty:(sometype)myproperty {     _myproperty = myproperty; }  @end 

obviously, former version more succinct , readable, there difference in behavior? synthesized getter , setter more sophisticated straightforward implementation here? declaration of property distinguishable introspection functions declaration of getter , setter? there other differences haven't thought of?

short answer: no difference. however, property attributes (copy or atomic) may require different accessor methods.

long answer: there group of introspection functions allow access @properties declared given class or protocol:

class_getproperty class_copypropertylist protocol_getproperty protocol_copypropertylist property_getname property_getattributes 

i don't think of these functions useful in production code, because implementation detail of class. also, there may getter/setter exposed in public interface , private property hidden in class extension.

oh, , there's 1 other difference: xcode highlights properties , plain getters differently :)


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 -