{"id":227321,"date":"2014-06-30T17:17:03","date_gmt":"2014-06-30T13:17:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=227321"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=227321","title":{"rendered":"<span class=\"post_title\">Multiple Delegate<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t\u0412 Cocoa \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0435\u043d <a href=\"http:\/\/en.wikipedia.org\/wiki\/Delegation_pattern\">\u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a>. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u2014 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u0440\u0443 weak \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0434\u0435\u043b\u0435\u0433\u0430\u0442.<\/p>\n<p>  \u0423 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0431\u0435\u0437 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f. \u0415\u0449\u0435 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, UITextField \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0443 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u043c\u0435\u0442\u043e\u0434 textFieldDidEndEditing:, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u043e, \u0438 \u0442.\u0434.<\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0437\u0430\u0434\u0430\u0447\u0443: \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u0440 \u043f\u043e\u0441\u044b\u043b\u0430\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0435 \u043e\u0434\u043d\u043e\u043c\u0443 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0443, \u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c, \u043f\u0440\u0438\u0447\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0447\u0435\u0440\u0435\u0437 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440<\/h4>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0442\u044f\u043d\u0443\u0442\u044b\u0439, \u043d\u043e \u0432\u0441\u0435 \u0436\u0435.<\/p>\n<p>  \u041d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 UITextField, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432 \u043d\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442, \u0438 \u0435\u0441\u043b\u0438 \u0442\u0435\u043a\u0441\u0442 \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0439, \u0442\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u0446\u0432\u0435\u0442. \u041f\u043b\u044e\u0441 \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0433 \u0432\u0432\u0435\u0441\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<p>  \u0422.\u0435 \u0445\u043e\u0442\u0438\u043c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:  <\/p>\n<pre><code class=\"objectivec\">@protocol PTCTextValidator &lt;NSObject&gt;  - (BOOL)textIsValid:(NSString *)text; - (BOOL)textLengthIsValid:(NSString *)text;  @end  @interface PTCVerifiableTextField : UITextField  @property (nonatomic, weak) IBOutlet id&lt;PTCTextValidator&gt; validator; @property (nonatomic, strong) UIColor *validTextColor UI_APPEARANCE_SELECTOR; @property (nonatomic, strong) UIColor *invalidTextColor UI_APPEARANCE_SELECTOR;  @property (nonatomic, readonly) BOOL isValid;  @end <\/code><\/pre>\n<p>  \u0418 \u0442\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0427\u0442\u043e\u0431\u044b PTCVerifiableTextField \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0431\u044b\u043b \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u043c \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u0443\u043f\u0435\u0440\u043a\u043b\u0430\u0441\u0441\u0430 (UITextField). \u041d\u043e \u0435\u0441\u043b\u0438 \u0442\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0442\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u043e\u0433\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e delegate \u0438\u0437\u0432\u043d\u0435.<br \/>  \u0422.\u0435. \u043d\u0438\u0436\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u043b\u043e\u043c\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u043b\u043e\u0433\u0438\u043a\u0443 PTCVerifiableTextField  <\/p>\n<pre><code class=\"objectivec\">PTCVerifiableTextField *textField = [PTCVerifiableTextField alloc] initWIthFrame:CGrectMake(0, 0, 100 20)];   textField.delegate = self;   [self.view addSubview:textField];   <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443: \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443  <\/p>\n<pre><code class=\"objectivec\">@property(nonatomic, assign) id&lt;UITextFieldDelegate&gt; delegate   <\/code><\/pre>\n<p>\u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u043e \u0441\u043e\u0431\u043e\u0439. \u041d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u0432 \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0435 \u0432 \u043d\u0435\u0433\u043e, \u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435.<br \/>  \u0422.\u0435 \u043d\u0443\u0436\u0435\u043d \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u043c\u0441\u044f \u0432 \u043d\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c.<\/p>\n<p>  \u0423 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u2014 \u0435\u0441\u043b\u0438 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u043d\u0430\u0434\u043e \u043a\u0430\u043a-\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0430\u043a\u043e\u0433\u043e \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0437\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043d\u0430\u0434\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Message Forwarding \u0438 NSProxy.<\/p>\n<h4>Message Forwarding<\/h4>\n<p>  Objective-C \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438. \u041c\u044b \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0435. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e, \u043c\u044b \u0448\u043b\u0435\u043c \u0435\u043c\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u0434 Message Forwarding \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0442.\u0435. \u0435\u0433\u043e \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>  \u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u043d \u043d\u0435 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442, \u0434\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043e\u0448\u0438\u0431\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u0440\u0430\u043d\u0442\u0430\u0439\u043c \u0434\u0430\u0441\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0448\u0430\u043d\u0441, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. <\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p>\n<p>  1. \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434, \u0442.\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c IMP (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>method_getImplementation(class_getInstanceMethod(subclass, aSelecor))<\/code>), \u0442\u043e \u0440\u0430\u043d\u0442\u0430\u0439\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0438\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p>  2. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>+(BOOL)resolveInstanceMethod:(SEL)aSEL<\/code> \u0438\u043b\u0438 <code>+(BOOL)resolveClassMethod:(SEL)name<\/code>, \u0435\u0441\u043b\u0438 \u0448\u043b\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0443. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438. \u0415\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f YES, \u0442\u043e \u0440\u0430\u043d\u0442\u0430\u0439\u043c \u0441\u043d\u043e\u0432\u043e \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c IMP \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0438\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p>  \u0415\u0449\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 <code>+(BOOL)respondsToSelector:(SEL)aSelector<\/code> \u0438 <code>+(BOOL)instancesRespondToSelector:(SEL)aSelector<\/code>, \u0435\u0441\u043b\u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d. \u041f\u0440\u0438\u0447\u0435\u043c, \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430, \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0448\u0430\u043d\u0441\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442!<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430:  <\/p>\n<pre><code class=\"objectivec\">+ (BOOL)resolveInstanceMethod:(SEL)aSEL {     if (aSEL == @selector(resolveThisMethodDynamically))     {           class_addMethod([self class], aSEL, (IMP) dynamicMethodIMP, &quot;v@:&quot;);           return YES;     }     return [super resolveInstanceMethod:aSel]; } <\/code><\/pre>\n<p>  3. \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 Fast Forwarding. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>-(id)forwardingTargetForSelector:(SEL)aSelector<\/code><br \/>  \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e. \u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e, \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430 \u0434\u043b\u044f \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f. Fast \u043e\u043d, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u043e\u0440\u0432\u0430\u0440\u0434\u0438\u043d\u0433 \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f NSInvoacation.<\/p>\n<p>  \u0414\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u044d\u0442\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u044b \u0432\u0441\u0435 \u0448\u0430\u0433\u0438. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0435\u0441\u043b\u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c self, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442: \u0432\u0438\u0434\u0438\u043c\u043e, \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c \u0432\u043d\u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u0438.<\/p>\n<p>  4. \u0414\u0432\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0448\u0430\u0433\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0444\u043e\u0440\u0432\u0430\u0440\u0434\u0438\u043d\u0433\u0430. \u041f\u043e\u0441\u043b\u0435 \u043d\u0438\u0445 \u0440\u0430\u043d\u0442\u0430\u0439\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u0442 NSInvocation, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector<\/code>. \u0415\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u0432\u043c\u0435\u0441\u0442\u043e NSInvocation \u0432\u0435\u0440\u043d\u0435\u0442 nil, \u0442\u043e \u0440\u0430\u043d\u0442\u0430\u0439\u043c \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>-(void)doesNotRecognizeSelector:(SEL)aSelector<\/code>, \u0442.\u0435. \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u043a\u0440\u044d\u0448.<\/p>\n<p>  5. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a invocation \u0441\u043e\u0437\u0434\u0430\u043d, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 <code>-(void)forwardInvocation:(NSInvocation *)anInvocation<\/code>.<br \/>  \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0432 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434, \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c invocation \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"objectivec\">- (void)forwardInvocation:(NSInvocation *)invocation {     SEL aSelector = [invocation selector];       if ([friend respondsToSelector:aSelector])         [invocation invokeWithTarget:friend];     else         [super forwardInvocation:invocation]; } <\/code><\/pre>\n<h4>NSProxy<\/h4>\n<p>  \u0418\u0437 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Method Forwarding \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 NSObject \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <code>-(NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector<\/code> \u0438 <code>-(void)forwardInvocation:(NSInvocation *)anInvocation<\/code>:.<\/p>\n<p>  \u041d\u043e \u0435\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434, \u0442\u043e \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0443\u0436\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u043a\u043b\u0430\u0441\u0441, \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f NSProxy, \u0438 \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u043a\u0441\u0438.<\/p>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c Multiple Delegate<\/h4>\n<p>  \u0418\u0442\u0430\u043a, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0437\u043d\u0430\u043d\u0438\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 Message Forwarding, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0430\u0448 PTCMultipleDelegate.<\/p>\n<p>  \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u043f\u0440\u043e\u043a\u0441\u0438, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441  <\/p>\n<pre><code class=\"objectivec\">@interface PTCMultipleDelegate : NSProxy  @property (nonatomic, weak, readonly) id mainDelegate; @property (nonatomic, strong, readonly) NSPointerArray *delegates; @property (nonatomic, assign, readonly) BOOL mainDelegateIsDelegator;  + (instancetype)newProxyForMainDelegate:(id)mainDelegate                               delegates:(NSArray *)delegates                 mainDelegateIsDelegator:(BOOL)mainDelegateIsDelegator;  @end <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u0435\u0441\u043b\u0438 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u043d\u0430\u0434\u043e \u043a\u0430\u043a-\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0430\u043a\u043e\u0433\u043e \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0437\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 \u0441\u043b\u0443\u0436\u0438\u0442 mainDelegate. \u0415\u0441\u043b\u0438 mainDelegate \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440, \u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 mainDelegate, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u0438\u0437 delegates.<\/p>\n<p>  \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"objectivec\">- (void)forwardInvocation:(NSInvocation *)invocation {     BOOL isMethodReturnSomething = (![[NSString stringWithCString:invocation.methodSignature.methodReturnType                                                          encoding:NSUTF8StringEncoding]                                       isEqualToString:@&quot;v&quot;]);      \tif ([self shouldCallMainDelegateForSelector:invocation.selector]) { \t\t[invocation invokeWithTarget:self.mainDelegate];     } \t \tNSInvocation *targetInvocation = invocation; \tif (isMethodReturnSomething) { \t\ttargetInvocation = [invocation copy]; \t} \t \tfor (id delegate in self.delegates) { \t\tif ([delegate respondsToSelector:invocation.selector]) { \t\t\t[targetInvocation invokeWithTarget:delegate];         }     } } <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 copy \u0434\u043b\u044f NSInvocation \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0432 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"objectivec\">@implementation NSInvocation (PTCUtils)  - (instancetype)copy { \tNSInvocation *copy = [NSInvocation invocationWithMethodSignature:[self methodSignature]]; \tNSUInteger argCount = [[self methodSignature] numberOfArguments]; \t \tfor (int i = 0; i &lt; argCount; i++) \t{ \t\tchar buffer[sizeof(intmax_t)]; \t\t[self getArgument:(void *)&buffer atIndex:i]; \t\t[copy setArgument:(void *)&buffer atIndex:i]; \t}      \treturn copy; }  @end <\/code><\/pre>\n<p>  \u0423 UITextField \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>-(void)keyboardInputChangedSelection:(id)selection<\/code><br \/>  \u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:  <\/p>\n<pre><code class=\"objectivec\">- (void)keyboardInputChangedSelection:(id)selection {     if ([self isEditing]) {         if ([self.delegate respondsToSelector:NSSelectorFromString(@&quot;keyboardInputChangedSelection:&quot;)]) {             if (self.delegate != self) {                 [self.delegate keyboardInputChangedSelection:selection];             }         }     } } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u043d\u0430\u0448 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a UITextField \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u043a\u0441\u0438 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u043c \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0431\u044f, \u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b. \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e mainDelegateIsDelegator. \u0415\u0441\u043b\u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 YES, \u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0438\u0437 mainDelegate \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0432 \u0441\u0430\u0431\u043a\u043b\u0430\u0441\u0441\u0435.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0432 \u0441\u0430\u0431\u043a\u043b\u0430\u0441\u0441\u0435, \u0430 \u043d\u0435 \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:  <\/p>\n<pre><code class=\"objectivec\">BOOL SelectorOverridenInSubclass(Class subclass, SEL aSelecor) {     if (method_getImplementation(class_getInstanceMethod(subclass, aSelecor)) !=         method_getImplementation(class_getInstanceMethod(class_getSuperclass(subclass), aSelecor))) {         return YES;     } else {         return NO;     } } <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435:  <\/p>\n<pre><code class=\"objectivec\">@interface PTCMultipleDelegate ()  @property (nonatomic, weak) id mainDelegate; @property (nonatomic, strong) NSPointerArray *delegates;  @end  @implementation PTCMultipleDelegate  + (instancetype)newProxyForMainDelegate:(id)mainDelegate                               delegates:(NSArray *)delegates                 mainDelegateIsDelegator:(BOOL)mainDelegateIsDelegator; {     return [[self alloc] initProxyMainDelegate:mainDelegate                                      delegates:delegates                        mainDelegateIsDelegator:mainDelegateIsDelegator]; }  - (instancetype)initProxyMainDelegate:(id)mainDelegate                             delegates:(NSArray *)delegates               mainDelegateIsDelegator:(BOOL)mainDelegateIsDelegator {     _mainDelegateIsDelegator = mainDelegateIsDelegator;     _mainDelegate = mainDelegate;     _delegates = [NSPointerArray weakObjectsPointerArray];     [delegates enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {         [_delegates addPointer:(__bridge void *)obj];     }];     return self; }  - (BOOL)shouldCallMainDelegateForSelector:(SEL)aSelector {     if ([self.mainDelegate respondsToSelector:aSelector]) {         if (self.mainDelegateIsDelegator) {             if (SelectorOverridenInSubclass([self.mainDelegate class], aSelector)) {                 return YES;             }         } else {             return YES;         }     }          return NO; }  - (BOOL)respondsToSelector:(SEL)aSelector {     if ([self shouldCallMainDelegateForSelector:aSelector]) {         return YES;     }      for (id delegate in self.delegates) { \t\tif ([delegate respondsToSelector:aSelector]) { \t\t\treturn YES;         }     }          return NO; }  - (NSMethodSignature *)methodSignatureForSelector:(SEL)sel {     return [[self.mainDelegate class] instanceMethodSignatureForSelector:sel]; }  - (void)forwardInvocation:(NSInvocation *)invocation {     BOOL isMethodReturnSomething = (![[NSString stringWithCString:invocation.methodSignature.methodReturnType                                                          encoding:NSUTF8StringEncoding]                                       isEqualToString:@&quot;v&quot;]);      \tif ([self shouldCallMainDelegateForSelector:invocation.selector]) { \t\t[invocation invokeWithTarget:self.mainDelegate];     } \t \tNSInvocation *targetInvocation = invocation; \tif (isMethodReturnSomething) { \t\ttargetInvocation = [invocation copy]; \t} \t \tfor (id delegate in self.delegates) { \t\tif ([delegate respondsToSelector:invocation.selector]) { \t\t\t[targetInvocation invokeWithTarget:delegate];         }     } }  @end <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0421\u044d\u043c\u043f\u043b<\/h4>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/fanruten\/MultipleDlegateSample\">GitHub<\/a>.      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/company\/e-Legion\/blog\/227321\/\"> http:\/\/habrahabr.ru\/company\/e-Legion\/blog\/227321\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t\u0412 Cocoa \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0435\u043d <a href=\"http:\/\/en.wikipedia.org\/wiki\/Delegation_pattern\">\u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a>. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u2014 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u0440\u0443 weak \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0434\u0435\u043b\u0435\u0433\u0430\u0442.<\/p>\n<p>  \u0423 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0431\u0435\u0437 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f. \u0415\u0449\u0435 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, UITextField \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0443 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u043c\u0435\u0442\u043e\u0434 textFieldDidEndEditing:, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u043e, \u0438 \u0442.\u0434.<\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0437\u0430\u0434\u0430\u0447\u0443: \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u0440 \u043f\u043e\u0441\u044b\u043b\u0430\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0435 \u043e\u0434\u043d\u043e\u043c\u0443 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0443, \u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c, \u043f\u0440\u0438\u0447\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0447\u0435\u0440\u0435\u0437 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-227321","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/227321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=227321"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/227321\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=227321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=227321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=227321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}