objective c - instance variables in @interface; header vs implementation -


is there difference between declaring private instance variable in header vs declaring in implementation?

in testobj.h

@interface testobj : nsobject {     int test; } @end 

vs in testobj.m

@interface testobj() {     int test; } @end 

both seem equivalent me, there actual difference between declaring instance variable in header vs in implementation, if not preferred? @interface within implementation file seems way declare private properties, have other purpose outside that?

the preference place private instance variables , properties in private class extension (in .m) , leave public interface file (.h) properties , methods part of public interface.

it helps isolate implementation details public interface , makes cleaner. ensures external classes not inadvertently alter private variables of class.

see class extensions extend internal implementation.


Comments

Popular posts from this blog

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

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

url rewriting - How to redirect a http POST with urlrewritefilter -