Can an Objective-C be its own delegate? Is this a good programming practice?

I know this is possible, but is it really good programming practice? The idea is to subclass UIAlertView and sign up as my own delegate in order to be able to add buttons and block handlers. That way, when I get alertView:clickedButtonAtIndex: I call the block that was passed.

I hope this is clear. Is this a good programming practice?

UPDATE: Here is my idea of ​​what I requested https://github.com/ianmurrays/IMAlertView . Any comments would be greatly appreciated.

+3
source share
2 answers

Yes, you are right, any class or object can be a delegate of any other, even itself. But I would say that this is not a good practice . You can create another class and delegate it to another. This expands the execution of the work, and readability is maintained. And in the future you can update your code with less labor.

+4
source

You can create a category to add block behavior to the UIAlertView . You can check it out this .

0
source

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


All Articles