{"id":268502,"date":"2015-11-18T22:07:04","date_gmt":"2015-11-18T19:07:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=268502"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=268502","title":{"rendered":"Objective-C \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043c\u0435\u0442\u043e\u0434 \u0438 self? + runtime"},"content":{"rendered":"<p>       \u041a\u0430\u043a self \u0438 _cmd \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u0435? \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 dispatch table \u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438? \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441? \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0443 \u0432\u0430\u0448\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 ARC \u0438 \u0432 MRC? \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 swizzling?<br \/>  \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e? \u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442!<\/p>\n<p>  <b>\u0412\u041d\u0418\u041c\u0410\u041d\u0418\u0415!<\/b> <br \/>  \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432\u2026 \u041f\u0440\u0438\u043d\u043e\u0448\u0443 \u0441\u0432\u043e\u0438 \u0438\u0437\u0432\u0438\u043d\u0435\u043d\u0438\u044f \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e \u043c\u043d\u043e\u0433\u0438\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c Objective-C \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/files\/199\/8d8\/b4d\/1998d8b4dfcb4e73baa98359ce74ace3.jpg\"\/><\/div>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0415\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430, \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0437\u0430\u0431\u0443\u0434\u0435\u043c, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b, \u043f\u043e\u0437\u0436\u0435 \u043c\u044b \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u044d\u0442\u043e\u043c\u0443 \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u2014 \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u044b \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438.<br \/>  \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0443\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0438\u0441\u043a \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 Objective-C, \u0434\u043b\u044f \u044d\u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0430\u0436\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/Objective-C#.D0.9A.D0.B0.D0.BA_.D1.80.D0.B0.D0.B1.D0.BE.D1.82.D0.B0.D0.B5.D1.82_.D0.BC.D0.B5.D1.85.D0.B0.D0.BD.D0.B8.D0.B7.D0.BC_.D1.81.D0.BE.D0.BE.D0.B1.D1.89.D0.B5.D0.BD.D0.B8.D0.B9\">\u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438<\/a>.<\/p>\n<p>  \u0418 \u0442\u0430\u043a, \u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/files\/de9\/38d\/97c\/de938d97cfb644ee93fcf6e22112bfc6.gif\"\/><\/div>\n<p>  \u041f\u043e\u0438\u0441\u043a \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e dispatch table \u0443 isa, \u0443\u0445\u043e\u0434\u044f \u0432\u043d\u0438\u0437. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432 Objective-C \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u0432\u043a\u043b\u044e\u0447\u0430\u044f private.<br \/>  \u0418 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434, \u0437\u043d\u0430\u044f \u0435\u0433\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440.<br \/>  \u041a\u043b\u044e\u0447\u0435\u043c \u0432 dispatch table \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f SEL (\u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440, <a href=\"http:\/\/habrahabr.ru\/post\/250955\/\">\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440<\/a>), \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c IMP (\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0441\u0430\u043c\u0430\u044f \u043e\u0431\u044b\u0447\u043d\u0430\u044f C \u0444\u0443\u043d\u043a\u0446\u0438\u044f)<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f? \u041e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>  \u041f\u043e \u0440\u0438\u0441\u0443\u043d\u043a\u0443, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u044d\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 dispatch table \u043a\u043b\u0430\u0441\u0441\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">... typedef struct objc_method *Method; ... struct objc_method {     SEL method_name                                          OBJC2_UNAVAILABLE;     char *method_types                                       OBJC2_UNAVAILABLE;     IMP method_imp                                           OBJC2_UNAVAILABLE; } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt;   @interface Human : NSObject  @property (copy, nonatomic) NSString *name;  @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &quot;Human.h&quot;   @implementation Human @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt; #import &lt;objc\/runtime.h&gt; #import &quot;Human.h&quot;   void printAllMethodClass(Class clazz) {     unsigned int count;     Method *methods = class_copyMethodList(clazz, &count);     for (int i = 0; i &lt; count; i++) {         Method method = methods[i];         SEL sel = method_getName(method);         NSLog(@&quot;%@&quot;, NSStringFromSelector(sel));     } }  int main(int argc, const char * argv[]) {     @autoreleasepool {         printAllMethodClass([Human class]);     }     return 0; } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">2015-11-14 22:02:03.744 TestingRuntime[71448:6200105] .cxx_destruct<br \/>  2015-11-14 22:02:03.746 TestingRuntime[71448:6200105] setName:<br \/>  2015-11-14 22:02:03.746 TestingRuntime[71448:6200105] name  <\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0417\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\u043c\u0435\u0442\u043e\u0434\u044b setName \u0438 name \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 property name  <\/div>\n<\/div>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 Human \u0438 \u0443\u0431\u0435\u0434\u0438\u043b\u0438\u0441\u044c, \u0447\u0442\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439. \u041f\u0440\u0430\u0432\u0434\u0430 \u0441\u0440\u0435\u0434\u0438 \u043d\u0430\u0448\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0441\u044f .cxx_destruct (\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f ARC \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043f\u043e\u043b\u0435\u0439, \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0445 release), \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043c\u043e\u0439 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<br \/>  \u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u0432 dispatch table. \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438? \u041e\u043d\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043a\u043b\u0430\u0441\u0441\u0430. \u0410 \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442? \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c include\/import? \u041d\u0435\u0442, \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a. <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u043b\u0438\u044f\u043d\u0438\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043d\u0430 dispatch table<\/b><\/p>\n<div class=\"spoiler_text\">\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human+FooMethod.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &quot;Human.h&quot;   @interface Human (FooMethod) @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human+FooMethod.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &quot;Human+FooMethod.h&quot;   @implementation Human (FooMethod)  - (void)fooMethod {     NSLog(@&quot;i send msg fooMethod&quot;); }  @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt; #import &quot;Human.h&quot;   int main(int argc, const char * argv[]) {     @autoreleasepool {         Human *human = [[Human alloc] init];         [human performSelector:@selector(fooMethod)];     }     return 0; } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">2015-11-14 22:24:20.862 TestingRuntime[71509:6208985] i send msg fooMethod  <\/div>\n<\/div>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0435 \u0443\u043f\u0430\u043b\u0430, \u0430 \u043c\u0435\u0442\u043e\u0434 \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u0435\u0442\u043e\u0434 \u00abfooMethod\u00bb \u0443\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 dispatch table. \u0417\u0430\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0432 \u043a\u043e\u0434\u0435 \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u00abHuman+FooMethod.h\u00bb. \u0417\u043d\u0430\u0447\u0438\u0442 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0444\u0430\u0439\u043b\u0430\u0445, \u0433\u0434\u0435 \u043c\u044b \u0435\u0435 \u0432\u043a\u043b\u044e\u0447\u0438\u043b\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f include\/import. \u0410 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u044f? \u041d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0438 \u043d\u0435 \u0432\u0430\u0436\u043d\u043e, \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0440\u0443\u043a\u0430\u043c\u0438. \u0414\u0430, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0435\u0442\u043e\u0434 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u043e\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt;   @interface Human : NSObject  @property (copy, nonatomic) NSString *name;  @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt; #import &lt;objc\/runtime.h&gt; #import &quot;Human.h&quot;  void methodInRuntime(Human *self, SEL _cmd) {     NSLog(@&quot;name self %@&quot;, self.name); }  int main(int argc, const char * argv[]) {     @autoreleasepool {         class_addMethod([Human class], @selector(methodInRuntime), (IMP)methodInRuntime, &quot;@@:&quot;);                  Human *human = [[Human alloc] init];         human.name = @&quot;ajjnix&quot;;         [human performSelector:@selector(methodInRuntime)];     }     return 0; } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <a href=\"https:\/\/developer.apple.com\/library\/mac\/documentation\/Cocoa\/Conceptual\/ObjCRuntimeGuide\/Articles\/ocrtTypeEncodings.html#\/\/apple_ref\/doc\/uid\/TP40008048-CH100\">\u0422\u0438\u043f\u044b<\/a><\/p><\/div>\n<\/div>\n<p>  \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u0432 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440, \u0447\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 self \u0438 _cmd(<a href=\"https:\/\/developer.apple.com\/library\/ios\/qa\/qa1669\/_index.html\">\u0447\u0442\u043e \u044d\u0442\u043e?<\/a>)<\/p>\n<p>  \u0417\u043d\u0430\u0447\u0438\u0442 \u043c\u0435\u0442\u043e\u0434 \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440. \u041d\u0435\u0441\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u044c?<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e self \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0438 \u0447\u0442\u043e \u0431\u043b\u043e\u043a \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 self \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (\u0442\u0435\u043c\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438). \u0418 \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432 \u0431\u043b\u043e\u043a\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441 \u0438\u043c\u0435\u043d\u0435\u043c self (\u0447\u0442\u043e \u043f\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432, \u0433\u0434\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f self).<br \/>  \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441: \u00ab\u041c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u043f\u043e\u0434\u0434\u0435\u043b\u0430\u0442\u044c self \u0438 _cmd \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435?\u00bb \u0414\u0430, \u043c\u043e\u0436\u0435\u043c. \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0432 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435, IMP \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043b\u044e\u0431\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u043c\u0443 \u0432\u0438\u0434\u0443 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043d\u0435\u0435 \u0432\u0441\u0435, \u0447\u0442\u043e \u0437\u0430\u0445\u043e\u0442\u0438\u043c.<\/p>\n<p>  \u0427\u0442\u043e \u043c\u044b \u0435\u0449\u0435 \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435? \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 ivar, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b, \u043f\u0440\u043e\u043f\u0435\u0440\u0442\u0438, \u043c\u0435\u0442\u043e\u0434\u044b, \u0443\u0434\u0430\u043b\u044f\u0442\u044c, \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0435\u0449\u0438. \u041d\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u043d\u0442\u0430\u0439\u043c, \u0430 \u043e \u043c\u0435\u0442\u043e\u0434\u0430\u0445.<\/p>\n<p>  \u041c\u044b \u043f\u043e\u0434\u043e\u0448\u043b\u0438 \u043a \u043f\u043e\u043d\u044f\u0442\u0438\u044e swizzling, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043c\u0435\u043d\u043e\u0439. <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">swizzling<\/b><\/p>\n<div class=\"spoiler_text\">\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt;   @interface Human : NSObject  - (NSString *)fname; - (NSString *)lname;  - (void)swizzling;  @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &quot;Human.h&quot; #import &lt;objc\/runtime.h&gt;   @implementation Human  - (NSString *)fname {     return @&quot;first name&quot;; }  - (NSString *)lname {     return  @&quot;last name&quot;; }  - (void)swizzling {     Method mfname = class_getInstanceMethod([self class], @selector(fname));     Method mlname = class_getInstanceMethod([self class], @selector(lname));     method_exchangeImplementations(mfname, mlname); }  @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt; #import &quot;Human.h&quot;   int main(int argc, const char * argv[]) {     @autoreleasepool {         Human *human = [[Human alloc] init];         NSLog(@&quot;my fname:%@&quot;, [human fname]);         NSLog(@&quot;my lname:%@&quot;, [human lname]);          [human swizzling];                  NSLog(@&quot;my fname:%@&quot;, [human fname]);         NSLog(@&quot;my lname:%@&quot;, [human lname]);     }     return 0; } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">2015-11-15 19:53:28.307 TestingRuntime[72180:6349571] my fname:first name<br \/>  2015-11-15 19:53:28.309 TestingRuntime[72180:6349571] my lname:last name<br \/>  2015-11-15 19:53:28.309 TestingRuntime[72180:6349571] my fname:last name<br \/>  2015-11-15 19:53:28.309 TestingRuntime[72180:6349571] my lname:first name  <\/div>\n<\/div>\n<p>  <\/div>\n<\/div>\n<p>  \u041c\u044b \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u041d\u0438\u043a\u0430\u043a\u043e\u0439 \u043c\u0430\u0433\u0438\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u043d\u0430\u0441 \u043d\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u0435\u0442\u043e\u0434\u044b.<\/p>\n<p>  \u0410 \u043a\u0430\u043a \u0436\u0435 isa? \u0412\u0435\u0434\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0437\u0434\u0435\u0441\u044c, \u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430? \u041c\u043e\u0436\u0435\u043c.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043c\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 runtime, \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u0430\u0434\u0440\u0435\u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt;   @interface Human : NSObject  - (void)humanMethod;  @end   @interface Human1 : Human  - (void)humanMethod1;  @end   @interface NoHuman : NSObject  @property (copy, nonatomic) NSString *foo;  - (void)noHumanMethod;  @end  <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &quot;Human.h&quot;   @implementation Human  - (void)humanMethod {     NSLog(@&quot;humanMethod&quot;); }  @end   @implementation Human1  - (void)humanMethod1 {     NSLog(@&quot;humanMethod1&quot;); }  @end   @implementation NoHuman  - (void)noHumanMethod {     NSLog(@&quot;noHumanMethod with property foo:%@&quot;, self.foo); }  @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt; #import &quot;Human.h&quot; #import &lt;objc\/runtime.h&gt;   int main(int argc, const char * argv[]) {     @autoreleasepool {         Human *human = [[Human alloc] init];         NSLog(@&quot;ptr %p, isa = %@&quot;, human, NSStringFromClass([human class]));         [human performSelector:@selector(humanMethod)];                  object_setClass(human, [Human1 class]);         NSLog(@&quot;ptr %p, isa = %@&quot;, human, NSStringFromClass([human class]));         [human performSelector:@selector(humanMethod)];         [human performSelector:@selector(humanMethod1)];                  object_setClass(human, [NoHuman class]);         NSLog(@&quot;ptr %p, isa = %@&quot;, human, NSStringFromClass([human class]));         NoHuman *noHuman = (NoHuman *)human;         noHuman.foo = @&quot;f o o&quot;;         [noHuman noHumanMethod];     }     return 0; } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">2015-11-15 22:40:45.960 TestingRuntime[72469:7427905] ptr 0x10020b8b0, isa = Human<br \/>  2015-11-15 22:40:45.961 TestingRuntime[72469:7427905] humanMethod<br \/>  2015-11-15 22:40:45.962 TestingRuntime[72469:7427905] ptr 0x10020b8b0, isa = Human1<br \/>  2015-11-15 22:40:45.962 TestingRuntime[72469:7427905] humanMethod<br \/>  2015-11-15 22:40:45.962 TestingRuntime[72469:7427905] humanMethod1<br \/>  2015-11-15 22:40:45.962 TestingRuntime[72469:7427905] ptr 0x10020b8b0, isa = NoHuman<br \/>  2015-11-15 22:40:45.962 TestingRuntime[72469:7427905] noHumanMethod with property foo:f o o  <\/div>\n<\/div>\n<p>  <\/div>\n<\/div>\n<p>  \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u044f \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b \u0437\u0430\u0431\u044b\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0447\u0442\u043e \u0432 Objective-C \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442. \u0422\u0430\u043a \u0432\u043e\u0442, \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u0435.<\/p>\n<p>  \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043a\u043b\u0430\u0441\u0441 \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441\u0430. \u0423 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u0441\u0432\u043e\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f dispatch table, \u0441\u0432\u043e\u0439 isa. \u0422\u0430\u043a\u0436\u0435 \u043e\u043d \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0441\u0432\u043e\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0432\u0445\u043e\u0434\u0430 (+initializer).<br \/>  \u041c\u044b \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0443 \u043c\u0435\u0442\u043e\u0434, \u043a\u0430\u043a \u0438 \u0434\u0435\u043b\u0430\u043b\u0438 \u044d\u0442\u043e \u0440\u0430\u043d\u0435\u0435. \u0417\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f, \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 dispatch table, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt;   @interface Human : NSObject  + (void)humanClassMethod; - (void)humanMethod;  @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &quot;Human.h&quot;   @implementation Human  - (void)humanMethod {     NSLog(@&quot;humanMethod&quot;); }  + (void)humanClassMethod {     NSLog(@&quot;humanClassMethod&quot;); }  @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt; #import &quot;Human.h&quot; #import &lt;objc\/runtime.h&gt;   void printAllMethodClass(Class clazz) {     unsigned int count;     Method *methods = class_copyMethodList(clazz, &count);     for (int i = 0; i &lt; count; i++) {         Method method = methods[i];         SEL sel = method_getName(method);         NSLog(@&quot;%@&quot;, NSStringFromSelector(sel));     } }  int main(int argc, const char * argv[]) {     @autoreleasepool {         printAllMethodClass([Human class]);          NSLog(@&quot;\\n\\n\\n&quot;);                  Class metaClass = object_getClass([Human class]);         printAllMethodClass(metaClass);     }     return 0; } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">2015-11-15 20:20:33.128 TestingRuntime[72303:6360119] humanMethod<br \/>  2015-11-15 20:20:33.129 TestingRuntime[72303:6360119] <\/p>\n<p>  2015-11-15 20:20:33.129 TestingRuntime[72303:6360119] humanClassMethod  <\/div>\n<\/div>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043b\u044f \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u0434\u0440\u0435\u0441 \u043c\u0435\u0442\u043e\u0434\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043a \u043d\u0443\u0436\u043d\u043e\u043c\u0443 \u0442\u0438\u043f\u0443.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/b><\/p>\n<div class=\"spoiler_text\">\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt;   @interface Human : NSObject  @property (copy, nonatomic) NSString *name;  - (NSString *)fooMethodWithArg1:(NSString *)arg1 arg2:(NSString *)arg2;  @end <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Human.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &quot;Human.h&quot;   @implementation Human  - (NSString *)fooMethodWithArg1:(NSString *)arg1 arg2:(NSString *)arg2 {     return [NSString stringWithFormat:@&quot;\\nname:%@ \\n_cmd:%@ \\narg1:%@ \\narg2:%@&quot;, self.name, NSStringFromSelector(_cmd), arg1, arg2]; }  @end  <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">main.m<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"objectivec\">#import &lt;Foundation\/Foundation.h&gt; #import &quot;Human.h&quot; #import &lt;objc\/runtime.h&gt;   int main(int argc, const char * argv[]) {     @autoreleasepool {                  SEL sel = @selector(fooMethodWithArg1:arg2:);         Method method = class_getInstanceMethod([Human class], sel);         IMP imp = method_getImplementation(method);          #define funcWithArg1AndArg2(imp) ((NSString * (*)())imp)         Human *human = [[Human alloc] init];         human.name = @&quot;ajjnix&quot;;                  NSString *result = funcWithArg1AndArg2(imp)(human, sel, @&quot;Hello &quot;, @&quot;world&quot;);         NSLog(@&quot;%@&quot;, result);                  NSLog(@&quot;\\n\\n\\n&quot;);                  NSString *result1 = funcWithArg1AndArg2(imp)(human, @selector(fake_selector), @&quot;Hello &quot;, @&quot;world&quot;);         NSLog(@&quot;%@&quot;, result1); #undef funcWithArg1AndArg2     }     return 0; } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u044b\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">2015-11-17 12:28:29.821 TestingRuntime[73269:8918838] <br \/>  name:ajjnix <br \/>  _cmd:fooMethodWithArg1:arg2: <br \/>  arg1:Hello <br \/>  arg2:world<br \/>  2015-11-17 12:28:29.823 TestingRuntime[73269:8918838] <\/p>\n<p>  2015-11-17 12:28:29.823 TestingRuntime[73269:8918838] <br \/>  name:ajjnix <br \/>  _cmd:fake_selector <br \/>  arg1:Hello <br \/>  arg2:world  <\/div>\n<\/div>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0439, \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u044f \u0441\u043c\u043e\u0433 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u044f\u0437\u044b\u043a\u0435 Objective-C.<br \/>  p.s. \u0438 \u0432 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438, \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 <a href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/Cocoa\/Conceptual\/ObjCRuntimeGuide\/Articles\/ocrtHowMessagingWorks.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e<\/a>               <\/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=\"http:\/\/habrahabr.ru\/post\/270913\/\"> http:\/\/habrahabr.ru\/post\/270913\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u041a\u0430\u043a self \u0438 _cmd \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u0435? \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 dispatch table \u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438? \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441? \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0443 \u0432\u0430\u0448\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 ARC \u0438 \u0432 MRC? \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 swizzling?<br \/>  \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e? \u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442!<\/p>\n<p>  <b>\u0412\u041d\u0418\u041c\u0410\u041d\u0418\u0415!<\/b> <br \/>  \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432\u2026 \u041f\u0440\u0438\u043d\u043e\u0448\u0443 \u0441\u0432\u043e\u0438 \u0438\u0437\u0432\u0438\u043d\u0435\u043d\u0438\u044f \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e \u043c\u043d\u043e\u0433\u0438\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c Objective-C \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/files\/199\/8d8\/b4d\/1998d8b4dfcb4e73baa98359ce74ace3.jpg\"\/><\/div>\n<p>  <\/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-268502","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/268502","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=268502"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/268502\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=268502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=268502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=268502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}