Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C "private" protocols?

I got a view controller class (MyViewController) that deals with a UIView subclass (MyView). I don't want to let any class except the view controller class know about the UIView subclass, so I cannot import MyView.h in MyViewController.h.

So, in MyViewController.m, I put

#import "MyViewController.h"
#import "MyView.h"

@interface MyViewController (PrivateObjects)

MyView *myView;

@end

...

However, to get feedback from MyView, I use a delegate. That delegate has to implement the MyViewDelegate protocol.

How can I implement the MyViewDelegate protocol inside MyViewController without having to #import MyView.h in MyViewController.h?

like image 464
ryyst Avatar asked Jul 25 '10 11:07

ryyst


1 Answers

@interface MyViewController (PrivateObjects) <MyViewDelegate>
....

(BTW, you can't declare a new ivar in a category.)

like image 181
kennytm Avatar answered Oct 10 '22 05:10

kennytm