Override inherited method as private in objective-c

I am creating a subclass of UIBarButtonItem to provide some specific functions.

The new class has an initializer, which is the only one that should be used when instantiating the class:

- (id) initWithSomeObject:(SomeObject *)param;

The problem is that all initializers from the UIBarButtonItem are still available, so I can instantiate my new class using something like

MyCustomUIBarButtonItem *button = [[MyCustomUIBarButtonItem alloc]  initWithBarButtonSystemItem:systemItem target:target action:action];

or something else...

Is there a way to hide initializers from UIBarButtomItem in my subclass so that they cannot be used?

+3
source share
2 answers

Just make it clear that no other initializer, except for this, should be used.

- , NSAssert(NO,@"Don't use this"); . .

+3

; Obj-C . freespace, , , , , .

, , . "" ( ) ​​ / Cocoa, , .

+1

Source: https://habr.com/ru/post/1755005/


All Articles