iphone - How to declare instance variables and methods not visible or usable outside of the class instance? -


i've looked through bunch of posts on subject. maybe didn't run across "the one" , point me in direction. question simple , has simple answer.

if have 2 ivars, say, "public_ivar" , "private_ivar", where/how should declare them public public , private not exposed in way looking @ header file?

same question in case of "public_method" , "private_method".

i clean header files (in other languages) expose methods , ivars want else see. should able publish header file , not run danger of accessing not supposed to. how do in objective-c.

for example, let's decide need use ivar keep track of data, counter or somthing that, between various class methods need access information. if ivar declared conventionally in header under @interface existence publicly advertised , usable creating instance of class. ideal scenario ivar not visible @ outside of class implementation.

you can declare instance variables or declared properties in class extension. since class extension declared in implementation file (i.e., not header file), won’t visible inspecting header file. instance, in header file:

@interface someclass : nsobject @end 

and in implementation file:

@interface someclass () @property (nonatomic, assign) int privateint; @end  @implementation someclass  @synthesize privateint; … @end 

or

@interface someclass () {     int privateint; } @end  @implementation someclass … @end 

note there’s nothing preventing access private/class extension instance variables (or accessor methods properties declared in class extension) during runtime. i’ve written rather detailed post answer question on stack overflow: does private @property create @private instance variable?

edit: instance variables in class extensions presented in wwdc 2010 session 144.

edit: "using clang/llvm 2.0 compiler, can declare properties , instance variables in class extension."

http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/objectivec/chapters/occategories.html#//apple_ref/doc/uid/tp30001163-ch20-sw1


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -