@protect & @private: visible question

Discussion in 'Mac Programming' started by Howiieque, Mar 26, 2009.

  1. macrumors regular

    Joined:
    Feb 1, 2009
    #1
    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".
     
  2. macrumors newbie

    Joined:
    Mar 23, 2009
    Location:
    Lexington, Ky
    #2
    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
     
  3. thread starter macrumors regular

    Joined:
    Feb 1, 2009
    #3
    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?!
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     
  5. thread starter macrumors regular

    Joined:
    Feb 1, 2009
    #5
    thank you.
    you thought it confusing also.
    i was afraid that i am not smart enough catch it.:)
     

Share This Page