Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Howiieque

macrumors regular
Original poster
Feb 1, 2009
120
0
HTML:
@protected
If the object is self, a protected field is visible. 
If the object is not self, access depends on its class: 
· If the object's class is the same as that of the receiver, the field is visible. 
· If the object inherits from the receiver's class, the field is not visible. (You can get around this by casting the object to the receiver's class.) 
· If the object has any other relation to the receiver's class, the field is not visible. 
@private
If the object is self, a private field is visible. 
If the object is not self:
· If the object's class is the same as that of the receiver, the field is visible. 
· In all other cases, the field is not visible. 
--from objective-c pocket reference
can give an detail expanation or code example, especially, "If the object is not self, access depends on its class".
 

danmanstx

macrumors newbie
Mar 23, 2009
18
0
Lexington, Ky
basically private can only be accessed in the class by functions designed to modified this data, protected is very similar, but it can also be modified by classes that are derived from the original class. this is my c++ understanding
 

Howiieque

macrumors regular
Original poster
Feb 1, 2009
120
0
basically, i know a little of them. but just don't quite understand what the boo says.
"If the object's class is the same as that of the receiver, the field is visible."
i can see the other object's fields, if it is of the same class as the receiver?!
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
That description is a bit confusing. Apple makes it pretty clear here (go down to the The Scope of Instance Variables section). Basically, @private ivars are only accessible to that class, @protected are accessible to that class and all subclasses, and @public are accessible to all classes.
 

Howiieque

macrumors regular
Original poster
Feb 1, 2009
120
0
thank you.
you thought it confusing also.
i was afraid that i am not smart enough catch it.:)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.