开发者

Is it possible to have private methods and properties visible to subclasses?

What I'm going for here is basically a class Extension that is also visible to subclasses. I suppose the effect could be accomplished by declaring the private methods and properties in a separate Category file with its own @implementation block independent of the class's. The superclass and each subclass could then #import t开发者_高级运维he header. That's the best I can think of, but it feels like unnecessary file pollution, and the practice of realizing private methods with Categories has largely been superseded by class Extensions. I'm thinking it's not possible, but I'm asking on the off-chance that someone cooler than me has thought of a better way.


You can follow your own suggestion (declaring the private methods in a separate header), but you can use an extension if you'd prefer, rather than a category.

Apple does exactly this with UIGestureRecognizer. Take a look in UIGestureRecognizerSubclass.h.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜