-1

I have created three classes, and one method in one of the classes, but I only want my other two classes to be able to call the method. Any guess how to do this.

Thanks.

  • 2
    Possible duplicate of [Friend class in Objective C](http://stackoverflow.com/questions/6006701/friend-class-in-objective-c) – JimmyB Apr 27 '16 at 12:01
  • 1
    implement `protocols` and those class will confirm to this protocol will have to methods implemention. – byJeevan Apr 27 '16 at 12:01
  • Possible duplicate of http://stackoverflow.com/questions/2241488/friend-classes-in-objective-c – JimmyB Apr 27 '16 at 12:01

1 Answers1

1

As mentioned in links given in the comments, a Category will get you similar behaviour in Objective-C. The difference, compared to C++, is that it's voluntary rather than enforced by the compiler.

Any class that imports the Category header can make the call and, even if the header isn't published, a programmer can call the method if the signature is known by declaring a Category interface (or ignoring a compiler warning).

If you're doing this as a way of reminding yourself not to call those methods, Categories work well. If you were trying to protect against someone else "hacking into" the methods, it would be little defense.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57