Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're over-thinking what "private" means. In ObjC, "private" just means "not visible." It doesn't mean "not callable." The way you make a method private is to not put it in your <code>.h</code> file, which declares your public interface.</p> <p>There is no way to control who passes a message. This is a key fact of ObjC and cannot (and should not) be changed. ObjC is a dynamic language. At runtime, I am free to generate selectors and call <code>performSelector:</code> on any object I want. Anything that stopped that would either (a) introduce significant performance penalties, or (b) break many very useful and common techniques in ObjC (probably both). ObjC is not Java or C#. It's not even C or C++. It's Smalltalk on top of C. It's a highly dynamic language and that has a lot of strengths. <a href="http://robnapier.net/blog/learning-cocoa-2-467" rel="nofollow">Unlearning other languages</a> is the first step towards becoming a good Cocoa developer.</p> <p>It would be nice to have a compiler-checked <code>@private</code> for methods (of which properties are just a special case), and it would especially be awesome to have a compiler-checked <code>@protected</code> for methods (these exist for ivars). These would make it <em>slightly</em> simpler to avoid some kinds of mistakes. But that's the only way you should be thinking about this. The goal is not to protect one part of the code from another part of the code. The other code is not the enemy. It's all written by people who want the program to work. The goal is to avoid mistakes. Correct naming, consistency, and the absolute elimination of warnings is how you achieve that in ObjC.</p> <p>So yes, I'd love to be able to put <code>@protected</code> in front of my <code>@property</code> declarations occasionally. Today you can't, and there is no real equivalent (I sometimes use a <code>+Protected</code> category in a separate header, but it's generally more trouble than its worth). But that said, having it wouldn't change very much, and I only find a case where I would even use this a few times a year. I can't think of single case where <code>@private</code> for a method would have been really useful, though.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload