Is iOS statement inside class right?

Suppose I create a subclass of UITextView, for example, myTextView. I will make this class my delegate. So, I need to implement delegate methods like

- (void)textViewDidBeginEditing:(UITextView *)textView { 

Should I declare this method anyway?

 - (void)textViewDidBeginEditing:(myTextView *)textView { 

it seems recursive to me, because I'm inside the myTextView class, defining a delegate that refers to itself ...

What is the right approach? thanks.

+4
source share
1 answer

Just for clarification, it’s better to implement methods such as those defined in the protocol:

  - (void)textViewDidBeginEditing:(UITextView *)textView 

If you implement protocol methods with your custom class type or any class type, the methods will still be called because type checking is not performed. The parameter will actually be your custom subclass. In any case, and again for clarification, I suggest having an internal composition if you want to deal with the Ivars of your subclass:

 - (void)textViewDidBeginEditing:(UITextView *)textView { MyTextView * myTextView = (MyTextView *)textView; ... } 
+4
source

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


All Articles