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.
Comments
Post a Comment