{"id":274627,"date":"2016-02-19T19:46:02","date_gmt":"2016-02-19T16:46:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=274627"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=274627","title":{"rendered":"\u0414\u043e \u0447\u0435\u0433\u043e \u0434\u043e\u0432\u043e\u0434\u0438\u0442 \u0438\u0434\u0435\u044f (Objective-C) \u2014 target-action \u043d\u0430 \u0431\u043b\u043e\u043a\u0430\u0445 \u0438 \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0430"},"content":{"rendered":"<p>       \u041f\u0440\u0438\u0448\u043b\u0430 \u043c\u043d\u0435 \u043a\u0430\u043a-\u0442\u043e \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u0438\u0434\u0435\u044f, \u0430 \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0431\u043b\u043e\u043a \u0438 \u043e\u0442\u0434\u0430\u0442\u044c \u0434\u043b\u044f target-action?<br \/>  \u0415\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 <a href=\"https:\/\/github.com\/zwaldowski\/BlocksKit\">BlocksKit<\/a> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0431\u043b\u043e\u043a\u0430, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u0442\u0430\u0440\u0433\u0435\u0442\u0430 \u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u0431\u043b\u043e\u043a\u0430 \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430. <\/p>\n<p>  \u0417\u0430\u0447\u0435\u043c \u0442\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f? <\/p>\n<p>  \u042f \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0431\u043b\u043e\u043a. \u0427\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u0441\u043a\u0430\u0436\u0435\u0442\u0435 \u0432\u044b? imp_implementationWithBlock + class_addMethod \u0438 \u0434\u0435\u043b\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u043e. \u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u043e\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435, \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0431\u043b\u043e\u043a\u0430 \u2014 \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>  \u041a\u0430\u043a \u043e\u0431\u043e\u0439\u0442\u0438 \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435?  <\/p>\n<pre><code class=\"objectivec\">    [button addTarget:self action:[self ax_lambda:^(UIButton *sender, UIEvent *event){         NSLog(@&quot;click on button %@, event = %@&quot;, sender, event);     }] forControlEvents:UIControlEventTouchUpInside];      [button addTarget:self action:[self ax_lambda:^{         NSLog(@&quot;click&quot;);     }] forControlEvents:UIControlEventTouchUpInside]; <\/code><\/pre>\n<p>  \u0418\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u043e\u0442 \u0442\u0430\u043a  <\/p>\n<pre><code class=\"objectivec\">    __block NSInteger sum = 0;     [self performSelector:[self ax_lambda:^(NSNumber *argA, NSNumber *argB) {         sum = [argA integerValue] + [argB integerValue];     }] withObject:@(2) withObject:@(3)];     \/\/sum \u2014 5      SEL selSum = [self ax_lambda:^NSInteger(NSInteger argA, NSInteger argB){         return argA + argB;     }];     NSInteger(*funcSum)(id, SEL, NSInteger, NSInteger) = (NSInteger(*)(id, SEL, NSInteger, NSInteger))objc_msgSend;     NSInteger sum2 = funcSum(self, selSum, 2, 3);     \/\/sum2 \u2014 5 <\/code><\/pre>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439, \u0447\u0442\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u043e \u0441\u0443\u0442\u0438, \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u044d\u0442\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 self \u0432 \u0432\u044b\u0437\u043e\u0432\u0435 \u0431\u043b\u043e\u043a\u0430. \u042d\u0442\u043e \u043a\u043e\u0440\u043d\u0435\u0432\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432\u0441\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f (\u0436\u0430\u043b\u044c, \u0447\u0442\u043e \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f).<br \/>  \u0420\u0430\u043d\u0435\u0435 \u044f \u0443\u0436\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0438\u0441\u0430\u043b <a href=\"https:\/\/habrahabr.ru\/post\/271255\/\">\u043e \u0431\u043b\u043e\u043a\u0430\u0445<\/a>, \u0438 \u043e\u0442\u043c\u0435\u0442\u0438\u043b, \u0447\u0442\u043e \u0431\u043b\u043e\u043a \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 NSInvocation.<br \/>  \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u0431\u043b\u043e\u043a\u0430 \u0438 \u0432 NSInvocation \u0443\u0431\u0440\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 self (\u0441\u0434\u0432\u0438\u043d\u0443\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b), \u0442\u043e \u0442\u043e\u0433\u0434\u0430 \u044f \u043f\u043e\u043b\u0443\u0447\u0443 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u0434\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0445\u043e\u0434\u0443 \u0434\u0435\u043b\u0430.<\/p>\n<p>  <\/p>\n<h2>AXProxyBlock<\/h2>\n<p>  \u0412\u043e\u043f\u0440\u043e\u0441, \u043a\u0430\u043a \u0432\u043a\u043b\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u0431\u043b\u043e\u043a\u0430? \u041a\u0430\u043a \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u0431\u043b\u043e\u043a\u0430?<br \/>  \u041e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u044f \u043f\u0438\u0448\u0443 \u044d\u0442\u0443 \u0444\u0440\u0430\u0437\u0443, \u043d\u043e \u0431\u043b\u043e\u043a \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442. \u041e\u0431\u044a\u0435\u043a\u0442 \u0432 objc \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u044d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430. \u0420\u0430\u0437 id \u2014 \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043f\u043e\u0437\u0432\u043e\u043b\u0435\u043d\u043e \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0435 <a href=\"http:\/\/clang.llvm.org\/docs\/AutomaticReferenceCounting.html#bridged-casts\">(__bridge, \u043f\u0440\u0438\u0432\u0435\u0442)<\/a>.<br \/>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0435\u0439\u043a\u043e\u0432\u044b\u0439 \u0431\u043b\u043e\u043a. \u041d\u0443 \u0438\u043b\u0438 \u043f\u0440\u043e\u043a\u0441\u0438 \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0430.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043c\u043e\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">typedef void(^AXProxyBlockInterpose)(NSInvocation *invocation);   @interface AXProxyBlock : NSProxy  + (instancetype)initWithBlock:(id)block;  - (void)setBeforeInvoke:(AXProxyBlockInterpose)beforeInvoke;  - (NSString *)blockSignatureStringCTypes;  @end <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f, setBeforeInvoke \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0431\u043b\u043e\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435\u00bb \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0431\u043b\u043e\u043a\u0430.<br \/>  blockSignatureStringCTypes \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430. \u0417\u0430\u0447\u0435\u043c \u043e\u043d \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435? \u041e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0434\u043d\u0435\u0435.<\/p>\n<p>  <a href=\"http:\/\/clang.llvm.org\/docs\/Block-ABI-Apple.html\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0447\u043d\u0435\u0442\u0441\u044f<\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u043b\u043e\u043a\u0430 \u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0441 \u043d\u0430\u0448\u0438\u043c\u0438 \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f\u043c\u0438.<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">typedef struct AXBlockStruct_1 {     unsigned long int reserved;     unsigned long int size;          void (*copy_helper)(void *dst, void *src);     void (*dispose_helper)(void *src);          const char *signature; } AXBlockStruct_1;  typedef struct AXBlockStruct {     void *isa;     int flags;     int reserved;     void (*invoke)(void *, ...);     struct AXBlockStruct_1 *descriptor; } AXBlockStruct;   typedef NS_ENUM(NSUInteger, AXBlockFlag) {     AXBlockFlag_HasCopyDispose = (1 &lt;&lt; 25),     AXBlockFlag_HasCtor = (1 &lt;&lt; 26),     AXBlockFlag_IsGlobal = (1 &lt;&lt; 28),     AXBlockFlag_HasStret = (1 &lt;&lt; 29),     AXBlockFlag_HasSignature = (1 &lt;&lt; 30) }; <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u043d\u0430\u0448\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c.   <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">@interface AXProxyBlock ()  {  \/\/  isa \u043f\u043e\u043b\u0435 \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 NSProxy, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043c     int _flags;     int _reserved;     IMP _invoke;     AXBlockStruct_1 *_descriptor;  \/\/  \u0433\u043e\u0442\u043e\u0432\u043e, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430         AXProxyBlockInterpose _beforeInvoke;     id _block;     NSMethodSignature *_blockMethodSignature;     IMP _impBlockInvoke; }  @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043b\u0430\u0441\u0441 \u0438\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c\u044b\u0439 \u0431\u043b\u043e\u043a:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u0435\u0439<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">- (instancetype)initWithBlock:(id)block {     if (self != nil) {         AXBlockStruct *blockRef = (__bridge AXBlockStruct *)block;         _flags = blockRef-&gt;flags;         _reserved = blockRef-&gt;reserved;         _descriptor = calloc(1, sizeof(AXBlockStruct_1));         _descriptor-&gt;size = class_getInstanceSize([self class]);                  BOOL flag_stret = _flags & AXBlockFlag_HasStret;         _invoke = (flag_stret ? (IMP)_objc_msgForward_stret : (IMP)_objc_msgForward); ... <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0430 \u0442\u043e\u0439 \u0436\u0435 <a href=\"http:\/\/clang.llvm.org\/docs\/Block-ABI-Apple.html\">\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 clang<\/a>. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0431\u043b\u043e\u043a\u0443 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0437\u043e\u0432\u0430. <\/p>\n<p>  \u041d\u043e \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c 2 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u044b\u0445 ivar, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440 \u0432\u044b\u0448\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u0438 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u0443\u0436\u0435 \u043a \u0432\u044b\u0437\u043e\u0432\u0443 \u0431\u043b\u043e\u043a\u0430 \u0438 \u043d\u0430 \u043d\u0438\u0445 \u044f \u0445\u043e\u0447\u0443 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e.<\/p>\n<pre><code class=\"objectivec\">        _impBlockInvoke = (IMP)blockRef-&gt;invoke;         _blockMethodSignature = [self blockMethodSignature]; <\/code><\/pre>\n<p>  _impBlockInvoke \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0431\u043b\u043e\u043a\u0430, \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f. \u042d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0440\u0443\u043a\u0430\u043c\u0438.<br \/>  _blockMethodSignature \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434-\u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0431\u043b\u043e\u043a\u0430. \u0427\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0434\u0430\u043b\u0435\u0435.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c NSMethodSignature \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">- (NSMethodSignature *)blockMethodSignature {     const char *signature = [[self blockSignatureStringCTypes] UTF8String];     return [NSMethodSignature signatureWithObjCTypes:signature]; }  - (NSString *)blockSignatureStringCTypes {     AXBlockStruct *blockRef = (__bridge AXBlockStruct *)_block;          const int flags = blockRef-&gt;flags;          void *signatureLocation = blockRef-&gt;descriptor;     signatureLocation += sizeof(unsigned long int);     signatureLocation += sizeof(unsigned long int);          if (flags & AXBlockFlag_HasCopyDispose) {         signatureLocation += sizeof(void(*)(void *dst, void *src));         signatureLocation += sizeof(void (*)(void *src));     }          const char *signature = (*(const char **)signatureLocation);     return [NSString stringWithUTF8String:signature]; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041c\u044b \u0431\u0435\u0440\u0435\u043c \u043d\u0430\u0448 \u0431\u043b\u043e\u043a, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u043d\u0435\u0433\u043e descriptor, \u043f\u043e\u0442\u043e\u043c \u0441\u043c\u0435\u0449\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u043d\u0443\u0436\u043d\u0443\u044e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0431\u043b\u043e\u043a\u0430 (const char *) \u0438 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c NSMethodSignature. NSMethodSignature \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043a\u043e\u043b-\u0432\u043e \u0438 \u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0442\u043f. <br \/>  \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e, \u043d\u043e \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u0444\u043b\u0430\u0433\u043e\u043c \u0441\u043c\u0443\u0449\u0430\u044e\u0442: \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u0431\u043b\u043e\u043a\u0430, \u0435\u0433\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0443 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043c\u0435\u0449\u0430\u0442\u044c\u0441\u044f \u0437\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u0438\u044f. <\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434\u0430 \u043d\u0430 \u0432\u044b\u0437\u043e\u0432 \u0431\u043b\u043e\u043a\u0430 \u0443 \u043c\u043e\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435\u0442, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0431\u0443\u0434\u0435\u0442 forwardInvocation, \u0430 \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d NSInvocation, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 methodSignatureForSelector, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043e\u0442\u0434\u0430\u0435\u043c \u043d\u0430\u0448 _blockMethodSignature.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">forwardInvocation<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">- (void)forwardInvocation:(NSInvocation *)anInvocation {     [anInvocation setTarget:_block];     if (_beforeInvoke) {         _beforeInvoke(anInvocation);     }     IMP imp = _impBlockInvoke;     [anInvocation invokeUsingIMP:imp]; } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041a\u043e\u0434 \u0437\u0434\u0435\u0441\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u044f\u0442\u0435\u043d (\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u043d\u043e\u0432\u0443\u044e \u0446\u0435\u043b\u044c \u043d\u0430 \u0432\u044b\u0437\u043e\u0432, \u0432\u044b\u0437\u0432\u0430\u043b\u0438 \u0431\u043b\u043e\u043a before \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442), \u043d\u043e \u0433\u0434\u0435 \u0432\u044b\u0437\u043e\u0432 [anInvocation invoke]?!<br \/>  \u042d\u0442\u043e \u0447\u0435\u0440\u043d\u0430\u044f \u043c\u0430\u0433\u0438\u044f. \u041c\u0435\u0442\u043e\u0434 invokeUsingIMP \u044d\u0442\u043e <a href=\"https:\/\/github.com\/nst\/iOS-Runtime-Headers\">private API, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0437\u0434\u0435\u0441\u044c, \u043a\u0430\u043a \u0438 \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e<\/a><\/p>\n<p>  <\/p>\n<h2>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0430\u0437\u043b \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c<\/h2>\n<p>  \u042f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0441\u0432\u043e\u0435\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0439 \u0438 \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441\u0440\u0430\u0437\u0443 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u044b \u0437\u0430\u0434\u0430\u0447\u0438, \u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044e \u0434\u043e\u0447\u0438\u0442\u0430\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043b\u044e\u0434\u0435\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0439\u0447\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043b\u044c\u043a\u043e\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u043a\u0430\u043a \u0441\u043e\u0431\u0438\u0440\u0430\u043d\u0438\u0435 \u043f\u0430\u0437\u043b\u0430 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0438. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u043b\u0430\u0431\u0438\u0442\u044c\u0441\u044f \u0438 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e.<\/p>\n<p>  \u041f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043c\u0435\u0442\u043e\u0434\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 ax_lambda. \u042d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u0434\u043b\u044f NSObject, \u043e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"objectivec\">SEL ax_lambda(id obj, id block, NSMutableArray *lambdas); <\/code><\/pre>\n<p>  \u0414\u0443\u043c\u0430\u044e \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043e\u0431\u0435\u0440\u0442\u043a\u0430. \u0418 \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u0442\u043e 3\u0439 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f. \u0421\u043f\u0435\u0440\u0432\u0430 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0430 \u043f\u043e\u0442\u043e\u043c \u0443\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u044b \u043a\u043e\u0434 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438.<\/p>\n<pre><code class=\"objectivec\">SEL ax_lambda(id obj, id block, NSMutableArray *lambdas) {     SEL selector = ax_generateFreeSelector(obj);          AXProxyBlockWithSelf *proxyBlock = [AXProxyBlockWithSelf initWithBlock:block];     [proxyBlock setBeforeInvoke:^(NSInvocation *invocation){         ax_offsetArgInInvocation(invocation);     }];     [lambdas addObject:proxyBlock];          IMP imp = imp_implementationWithBlock(proxyBlock);     NSString *signatureString = [proxyBlock blockSignatureStringCTypes];     class_addMethod([obj class], selector, imp, [signatureString UTF8String]);          return selector; } <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0437\u043b. \u041a\u043b\u0430\u0441\u0441 AXProxyBlockWithSelf \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u0434\u0430\u043b\u0435\u0435, \u043f\u043e\u043a\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u043e\u043a \u043a\u043b\u0430\u0441\u0441\u0430 AXProxyBlock \u043a\u0430\u043a \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c. <br \/>  \u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043b\u043e\u043a \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440, \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u0430\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430. \u0418\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0441 \u043f\u0440\u043e\u043a\u0441\u0438\u0431\u043b\u043e\u043a\u0430, \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u0443\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043e\u0442\u0434\u0430\u0441\u0442 \u0442\u043e\u0436\u0435 \u043f\u0440\u043e\u043a\u0441\u0438 (\u0432 AXProxyBlock \u044d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430, \u043d\u043e \u0432 AXProxyBlockWithSelf \u043e\u043d\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0438 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e \u0434\u0430\u043b\u0435\u0435), \u043d\u0443 \u0430 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e. \u0422\u0430\u043a \u0437\u0430\u0447\u0435\u043c \u0436\u0435 3\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440?<\/p>\n<p>  \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 imp_implementationWithBlock \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0430 (Block_copy). \u041f\u043e\u043b\u0435 copy_helper \u0432 \u0431\u043b\u043e\u043a\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u043e\u043a\u0441\u0438 \u0431\u043b\u043e\u043a\u0430 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u044f \u0441\u043e\u0437\u0434\u0430\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0438\u0434\u0430 void (*)(void *dst, void *src), \u044f \u043d\u0435 \u0441\u043c\u043e\u0433\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0412 src \u043f\u0440\u0438\u0434\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043c\u043e\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u0437\u043e\u0432 imp_implementationWithBlock \u043d\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 proxyBlock (\u0438 proxyBlock \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438). \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0440\u043e\u043a \u0436\u0438\u0437\u043d\u0438 \u0431\u043b\u043e\u043a\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0441\u0440\u043e\u043a\u0430 \u0436\u0438\u0437\u043d\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0445\u0440\u0430\u043d\u044f\u0449\u0435\u0439 \u0435\u0433\u043e. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0435\u0439 \u0441\u0440\u043e\u043a \u0436\u0438\u0437\u043d\u0438 \u0431\u043b\u043e\u043a\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d \u0441\u0440\u043e\u043a\u043e\u043c \u0436\u0438\u0437\u043d\u0438 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">AXLambda.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">SEL ax_lambda(id obj, id block, NSMutableArray *lambdas);  @interface NSObject (AX_Lambda)  - (SEL)ax_lambda:(id)block;  @end <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">AXLambda.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">static char kAX_NSObjectAssociatedObjectKey;   @interface NSObject (_AX_Lambda)  @property (copy, nonatomic) NSMutableArray *ax_lambdas;  @end   @implementation NSObject (_AX_Lambda)  @dynamic ax_lambdas;  - (void)setAx_lambdas:(NSMutableArray *)lambdas {     objc_setAssociatedObject(self, &kAX_NSObjectAssociatedObjectKey, lambdas, OBJC_ASSOCIATION_RETAIN_NONATOMIC); }  - (NSMutableArray *)ax_lambdas {     NSMutableArray *marrey = objc_getAssociatedObject(self, &kAX_NSObjectAssociatedObjectKey);     if (marrey == nil) {         self.ax_lambdas = [NSMutableArray array];     }     return objc_getAssociatedObject(self, &kAX_NSObjectAssociatedObjectKey); }  @end  @implementation NSObject (AX_Lambda)  - (SEL)ax_lambda:(id)block {     return ax_lambda(self, block, self.ax_lambdas); }  @end <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0443 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 SEL ax_lambda(id obj, id block, NSMutableArray *lambdas);  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">SEL ax_generateFreeSelector(id obj)<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">SEL ax_generateFreeSelector(id obj) {     SEL selector;     NSMutableString *mstring = [NSMutableString string];     do {         [mstring setString:@&quot;ax_rundom_selector&quot;];         u_int32_t rand = arc4random_uniform(UINT32_MAX);         [mstring appendFormat:@&quot;%zd&quot;, rand];         selector = NSSelectorFromString(mstring);     } while ([obj respondsToSelector:selector]);     return selector; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">void ax_offsetArgInInvocation(NSInvocation *invocation)<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">void ax_offsetArgInInvocation(NSInvocation *invocation) {     void *foo = malloc(sizeof(void*));     NSInteger arguments = [[invocation methodSignature] numberOfArguments];     for (NSInteger i = 1; i &lt; arguments-1; i++) { \/\/i = 0 is self         [invocation getArgument:foo atIndex:i+1];         [invocation setArgument:foo atIndex:i];     }          free(foo); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h2>\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441 NSMethodSignature \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f stringWithFormat \u0438 NSArray<\/h2>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b NSInvocation \u0438 NSMethodSignature. \u042f \u0434\u0443\u043c\u0430\u043b \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u044d\u0442\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e, \u043d\u043e \u043f\u0440\u0438\u0448\u0435\u043b \u043a \u0432\u044b\u0432\u043e\u0434\u0443, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u043d\u0435 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b, \u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 (\u0432 \u0440\u0430\u0437\u0431\u043e\u0440\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430), \u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u0440\u044f\u043c\u043e \u0437\u0434\u0435\u0441\u044c.<\/p>\n<p>  \u041c\u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0431\u044b\u043b \u043c\u0435\u0442\u043e\u0434, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0437 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0432\u043e\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"objectivec\">    NSString *format = @&quot;%@, foo:%@, hello%@&quot;;     NSArray *input = @[@(12), @(13), @&quot; world&quot;];     NSString *result = [NSString ax_stringWithFormat:format array:input];     \/\/result \u2014 @&quot;12, foo:13, hello world&quot; <\/code><\/pre>\n<p>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043d\u0430\u0445\u043e\u0434\u0438\u043b \u043d\u0430 SO \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 (<a href=\"http:\/\/stackoverflow.com\/questions\/1058736\/how-to-create-a-nsstring-from-a-format-string-like-xxx-yyy-and-a-nsarr\">\u043f\u0435\u0440\u0432\u044b\u0439<\/a>, <a href=\"http:\/\/stackoverflow.com\/questions\/8273380\/converting-nsarray-contents-to-a-varargs-with-arc-for-use-with-nsstring-initwi\">\u0432\u0442\u043e\u0440\u043e\u0439<\/a>). \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u044f \u043d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c (\u0443 \u043a\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u2014 \u043e\u0442\u043f\u0438\u0448\u0438\u0442\u0435, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430) \u043d\u0430 ARC, \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0431\u044b\u043b \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<p>  \u041d\u0435 \u0434\u0435\u043b\u0430\u044f \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043e\u0431\u0445\u043e\u0434\u043e\u0432 \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f\u043c\u0438, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0438\u0434 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"objectivec\">+ (instancetype)ax_stringWithFormat:(NSString *)format array:(NSArray *)arguments; <\/code><\/pre>\n<p>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0443 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c  <\/p>\n<pre><code class=\"objectivec\">- (instancetype)initWithFormat:(NSString *)format arguments:(va_list)argList NS_FORMAT_FUNCTION(1,0); <\/code><\/pre>\n<p>  \u041d\u043e \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f (\u0438 \u0441\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430) \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c va_list (<a href=\"http:\/\/www.cplusplus.com\/reference\/cstdarg\/va_list\/\">\u0447\u0442\u043e \u044d\u0442\u043e<\/a> \u0438 <a href=\"http:\/\/www.cplusplus.com\/reference\/cstdarg\/va_start\/\">\u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/a>). <br \/>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">+ (instancetype)ax_string:(NSString *)format, &#8230;<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">+ (instancetype)ax_string:(NSString *)format, ... {     va_list list;     va_start(list, format);     NSString *str = [[NSString alloc] initWithFormat:format arguments:list];     va_end(list);     return str; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043a\u0430\u043a \u0435\u0433\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0438\u0437 NSArray.<\/p>\n<p>  <a href=\"https:\/\/developer.apple.com\/library\/mac\/documentation\/Cocoa\/Reference\/Foundation\/Classes\/NSInvocation_Class\/\">NSInvocation<\/a> \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0438\/\u0438\u043b\u0438 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438.<br \/>  \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 NSInvocation \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c NSMethodSignature.<br \/>  <a href=\"https:\/\/developer.apple.com\/library\/mac\/documentation\/Cocoa\/Reference\/Foundation\/Classes\/NSMethodSignature_Class\/index.html#\/\/apple_ref\/doc\/c_ref\/NSMethodSignature\">NSMethodSignature<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434, \u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f, \u0442\u0438\u043f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041f\u043e \u044d\u0442\u043e\u043c \u043e\u0447\u0435\u043d\u044c \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0441\u044f <a href=\"https:\/\/developer.apple.com\/library\/mac\/documentation\/Cocoa\/Reference\/Foundation\/Classes\/NSInvocation_Class\/\">\u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>  <\/p>\n<blockquote><p>NSInvocation does not support invocations of methods with either variable numbers of arguments or union arguments.<\/p><\/blockquote>\n<p>  \u0412\u0435\u0434\u044c \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043a\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e\/\u043c\u0435\u0442\u043e\u0434 \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u043a\u043e\u043b-\u0432\u043e\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  \u0410 \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e? \u0415\u0441\u043b\u0438 \u044f \u0441\u0430\u043c \u0437\u043d\u0430\u044e \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c? \u0422\u043e\u0433\u0434\u0430 \u044f \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 4 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0438 \u0442\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u044d\u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. <br \/>  NSMethodSignature \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443, \u0435\u0441\u043b\u0438 \u0441\u0430\u043c\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432\u044b\u0448\u0435. NSArray \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u041a\u0430\u043a \u044f \u0443\u0436\u0435 <a href=\"https:\/\/habrahabr.ru\/post\/270913\/\">\u043f\u0438\u0441\u0430\u043b<\/a>, \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c self \u0438 _cmd \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u0432 \u043d\u0435\u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">+ (NSMethodSignature *)ax_generateSignatureForArguments:(NSArray *)arguments<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">+ (NSMethodSignature *)ax_generateSignatureForArguments:(NSArray *)arguments {     NSInteger count = [arguments count];     NSInteger sizeptr = sizeof(void *);     NSInteger sumArgInvoke = count + 3; \/\/ self + _cmd + \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u043f\u0440\u043e \u0442\u043e \u0447\u0442\u043e \u0432 \u043c\u0435\u0442\u043e\u0434 \u0435\u0449\u0435 \u0438 \u0444\u043e\u0440\u043c\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f     NSInteger offsetReturnType = sumArgInvoke * sizeptr;          NSMutableString *mstring = [[NSMutableString alloc] init];     [mstring appendFormat:@&quot;@%zd@0:%zd&quot;, offsetReturnType, sizeptr];     for (NSInteger i = 2; i &lt; sumArgInvoke; i++) {         [mstring appendFormat:@&quot;@%zd&quot;, sizeptr * i];     }     return [NSMethodSignature signatureWithObjCTypes:[mstring UTF8String]]; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0434\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/developer.apple.com\/library\/mac\/documentation\/Cocoa\/Conceptual\/ObjCRuntimeGuide\/Articles\/ocrtTypeEncodings.html\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0442\u0438\u043f\u044b \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<br \/>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443, \u044f \u043e\u0447\u0435\u043d\u044c \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443.<\/p>\n<p>  \u041d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u0438 \u0435\u0433\u043e \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435, \u043d\u043e \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c). \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c sizeof(void*) \u0431\u0443\u0434\u0435\u0442 8 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 3\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u044f self + _cmd + \u0444\u043e\u0440\u043c\u0430\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u0438 \u0442\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c 6 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. 6\u04458 = 48<br \/>    @48<br \/>  \u0417\u0430\u0442\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 self \u0438 _cmd. self \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u0445, \u043f\u043e \u044d\u0442\u043e\u043c\u0443<br \/>    @48@0:8<br \/>  \u0417\u0430\u0442\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442<br \/>    @48@0:8@16<br \/>  \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b<br \/>    @48@0:8@16@24@32@40<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0438\u043c\u0435\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c NSInvocation  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">+ (instancetype)ax_stringWithFormat:(NSString *)format array:(NSArray *)arrayArguments<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">+ (instancetype)ax_stringWithFormat:(NSString *)format array:(NSArray *)arrayArguments {     NSMethodSignature *methodSignature = [self ax_generateSignatureForArguments:arrayArguments];     NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];     [invocation setTarget:self];     [invocation setSelector:@selector(ax_string:)];          [invocation setArgument:&format atIndex:2];     for (NSInteger i = 0; i &lt; [arrayArguments count]; i++) {         id obj = arrayArguments[i];         [invocation setArgument:(&obj) atIndex:i+3];     }          [invocation invoke];          __autoreleasing NSString *string;     [invocation getReturnValue:&string];          return string; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c, \u0435\u0441\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0448\u0435, \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 + (instancetype)ax_string:(NSString *)format,\u2026  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">+ (instancetype)ax_stringWithFormat:(NSString *)format array:(NSArray *)arrayArguments {     NSMethodSignature *methodSignature = [self ax_generateSignatureForArguments:arrayArguments];     NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];      [invocation setTarget:self];     [invocation setSelector:@selector(stringWithFormat:)];          [invocation setArgument:&format atIndex:2];     for (NSInteger i = 0; i &lt; [arrayArguments count]; i++) {         id obj = arrayArguments[i];         [invocation setArgument:(&obj) atIndex:i+3];     }          [invocation invoke];          __autoreleasing NSString *string;     [invocation getReturnValue:&string];          return string; }  \/\/https:\/\/developer.apple.com\/library\/mac\/documentation\/Cocoa\/Conceptual\/ObjCRuntimeGuide\/Articles\/ocrtTypeEncodings.html + (NSMethodSignature *)ax_generateSignatureForArguments:(NSArray *)arguments {     NSInteger count = [arguments count];     NSInteger sizeptr = sizeof(void *);     NSInteger sumArgInvoke = count + 3; \/\/self + _cmd + (NSString *)format     NSInteger offsetReturnType = sumArgInvoke * sizeptr;          NSMutableString *mstring = [[NSMutableString alloc] init];     [mstring appendFormat:@&quot;@%zd@0:%zd&quot;, offsetReturnType, sizeptr];     for (NSInteger i = 2; i &lt; sumArgInvoke; i++) {         [mstring appendFormat:@&quot;@%zd&quot;, sizeptr * i];     }     return [NSMethodSignature signatureWithObjCTypes:[mstring UTF8String]]; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u044b \u0437\u0430\u0434\u0430\u0447\u0438 \u2014 \u043a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0435 1 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432 \u0431\u043b\u043e\u043a \u043d\u0435\u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043d\u043e?<\/h2>\n<p>  \u0411\u044b\u043b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 \u0431\u043b\u043e\u043a\u0430 \u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0411\u044b\u043b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u0438 \u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043d\u044e\u0430\u043d\u0441\u044b \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e.<\/p>\n<p>  \u0411\u043b\u043e\u043a, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c\u044b\u0439 \u0432 imp_implementationWithBlock, \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 ax_lambda \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0438 \u0432 NSInvocation \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435 \u0432\u0435\u0440\u043d\u043e.<\/p>\n<p>  \u041a\u043b\u0430\u0441\u0441 AXProxyBlockWithSelf \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0432 \u043d\u0435\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u043e\u043a\u0441\u0438\u0431\u043b\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0443\u0436\u0435 \u0441\u043c\u0435\u0441\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430.<br \/>  \u041d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u2014 (NSString *)blockSignatureStringCTypes<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">&#8212; (NSString *)blockSignatureStringCTypes<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">- (NSString *)blockSignatureStringCTypes {     NSString *signature = [super blockSignatureStringCTypes];     NSString *unformatObject = [signature ax_unformatDec];     NSString *formatNewSignature = [self addSelfToFormat:unformatObject];          NSArray *byteSignature = [signature ax_numbers];     NSArray *byteNewSignature = [self changeByteSignature:byteSignature];          return [NSString ax_stringWithFormat:formatNewSignature array:byteNewSignature]; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418\u0442\u0430\u043a, \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0431\u043b\u043e\u043a\u0430, \u0441 \u0442\u0438\u043f\u0430\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u043c, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u0438 \u0442\u043f<br \/>  \u041d\u0443\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0438 \u0441\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0438\u0434 \u0444\u043e\u0440\u043c\u0430\u0442 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">- (NSString *)ax_unformatDec {     NSCharacterSet *characterSet = [NSCharacterSet decimalDigitCharacterSet];     NSPredicate *predicate = [NSPredicate predicateWithFormat:@&quot;length &gt; 0&quot;];     NSArray *separated = [[self componentsSeparatedByCharactersInSet:characterSet] filteredArrayUsingPredicate:predicate];     NSString *format = [separated componentsJoinedByString:@&quot;%@&quot;];     if ([[self lastSubstring] isEqualToString:[format lastSubstring]] ) {         return format;     } else {         return [format stringByAppendingString:@&quot;%@&quot;];     } }  - (NSString *)lastSubstring {     NSInteger lastIndex = [self length] - 1;     return [self substringFromIndex:lastIndex]; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u0434\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/developer.apple.com\/library\/mac\/documentation\/Cocoa\/Conceptual\/ObjCRuntimeGuide\/Articles\/ocrtTypeEncodings.html\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0442\u0438\u043f\u044b \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \\&quot;\u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446\\&quot; \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0435 \u043c\u0435\u0441\u0442\u043e<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">- (NSString *)addSelfToFormat:(NSString *)format {     NSMutableArray *marray = [[format componentsSeparatedByString:@&quot;?&quot;] mutableCopy];     [marray insertObject:@&quot;?%@@&quot; atIndex:1];     return [marray componentsJoinedByString:@&quot;&quot;]; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c NSArray \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">- (NSArray *)ax_numbers {     NSString *pattern = @&quot;\\\\d+&quot;;     NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil];     NSRange fullRange = NSMakeRange(0, [self length]);     NSArray *matches = [regex matchesInString:self options:NSMatchingReportProgress range:fullRange];          NSMutableArray *numbers = [NSMutableArray array];     for (NSTextCheckingResult *checkingResult in matches) {         NSRange range = [checkingResult range];         NSString *numberStr = [self substringWithRange:range];         NSNumber *number = @([numberStr integerValue]);         [numbers addObject:number];     }          return numbers; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">- (NSArray *)changeByteSignature:(NSArray *)byteSignature {     NSInteger value = sizeof(void *);     NSMutableArray *marray = [NSMutableArray array];     for (NSNumber *number in byteSignature) {         NSInteger offset = [number integerValue] + value;         [marray addObject:@(offset)];     }     [marray insertObject:@0 atIndex:1];     return marray; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0443 \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u043e\u0432\u0443\u044e \u0444\u043e\u0440\u043c\u0430\u0442-\u0441\u0442\u0440\u043e\u043a\u0443 \u0438 NSArray \u0441 \u043d\u043e\u0432\u044b\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u043c. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, \u0441\u043c\u0435\u0449\u0435\u043d \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0443 \u0438 \u0432\u044b\u0437\u0432\u0430\u043d \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0431\u043b\u043e\u043a.<\/p>\n<p>  <a href=\"https:\/\/github.com\/ajjnix\/AXBlock\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0437\u0434\u0435\u0441\u044c.<\/a> \u042d\u0442\u043e \u0431\u044b\u043b \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442, \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u0431\u044b\u043b\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445. \u041d\u043e \u044f \u0440\u0430\u0434, \u0447\u0442\u043e \u0441\u043c\u043e\u0433 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e. \u0422\u0430\u043a \u0436\u0435 \u044f \u0440\u0430\u0434, \u0447\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043c\u043e\u0433 \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u044b\u043b\u043e\u0436\u0438\u0432 <a href=\"http:\/\/stackoverflow.com\/a\/35039384\/4759124\">\u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/a> \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c NSArray \u043d\u0430 SO.<br \/>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0432 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0435 \u0438 \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043d\u0430 \u0431\u043b\u043e\u043a\u0438.               <\/p>\n<div class=\"clear\"><\/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=\"https:\/\/habrahabr.ru\/post\/276599\/\"> https:\/\/habrahabr.ru\/post\/276599\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u041f\u0440\u0438\u0448\u043b\u0430 \u043c\u043d\u0435 \u043a\u0430\u043a-\u0442\u043e \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u0438\u0434\u0435\u044f, \u0430 \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0431\u043b\u043e\u043a \u0438 \u043e\u0442\u0434\u0430\u0442\u044c \u0434\u043b\u044f target-action?<br \/>  \u0415\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 <a href=\"https:\/\/github.com\/zwaldowski\/BlocksKit\">BlocksKit<\/a> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0431\u043b\u043e\u043a\u0430, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u0442\u0430\u0440\u0433\u0435\u0442\u0430 \u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u0431\u043b\u043e\u043a\u0430 \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430. <\/p>\n<p>  \u0417\u0430\u0447\u0435\u043c \u0442\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f? <\/p>\n<p>  \u042f \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0431\u043b\u043e\u043a. \u0427\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u0441\u043a\u0430\u0436\u0435\u0442\u0435 \u0432\u044b? imp_implementationWithBlock + class_addMethod \u0438 \u0434\u0435\u043b\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u043e. \u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u043e\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435, \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0431\u043b\u043e\u043a\u0430 \u2014 \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>  \u041a\u0430\u043a \u043e\u0431\u043e\u0439\u0442\u0438 \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435?  <\/p>\n<pre><code class=\"objectivec\">    [button addTarget:self action:[self ax_lambda:^(UIButton *sender, UIEvent *event){         NSLog(@&quot;click on button %@, event = %@&quot;, sender, event);     }] forControlEvents:UIControlEventTouchUpInside];      [button addTarget:self action:[self ax_lambda:^{         NSLog(@&quot;click&quot;);     }] forControlEvents:UIControlEventTouchUpInside]; <\/code><\/pre>\n<p>  \u0418\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u043e\u0442 \u0442\u0430\u043a  <\/p>\n<pre><code class=\"objectivec\">    __block NSInteger sum = 0;     [self performSelector:[self ax_lambda:^(NSNumber *argA, NSNumber *argB) {         sum = [argA integerValue] + [argB integerValue];     }] withObject:@(2) withObject:@(3)];     \/\/sum \u2014 5      SEL selSum = [self ax_lambda:^NSInteger(NSInteger argA, NSInteger argB){         return argA + argB;     }];     NSInteger(*funcSum)(id, SEL, NSInteger, NSInteger) = (NSInteger(*)(id, SEL, NSInteger, NSInteger))objc_msgSend;     NSInteger sum2 = funcSum(self, selSum, 2, 3);     \/\/sum2 \u2014 5 <\/code><\/pre>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439, \u0447\u0442\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c.  <\/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-274627","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/274627","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=274627"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/274627\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=274627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=274627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=274627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}