IOS高階開發 Runtime(三)

2021-07-11 17:53:08 字數 1587 閱讀 6680

11、系統類的方法實現部分替換

- (void) methodexchange

列印結果:(仔細看log)

2013-07-26 16:33:22.776 highoc[7104:c07] sssaaaass

2013-07-26 16:33:22.778 highoc[7104:c07] sssaaaass

12、自定義類的方法實現部分替換

- (void) justlog1

- (void) justlog2

- (void) methodsetimplementation

//[self methodsetimplementation];

//[self justlog2];

13、覆蓋系統方法

imp cfuncpointer;

imp cfuncpointer1;

imp cfuncpointer2;

nsstring* customuppercasestring(id

self,sel

_cmd)

nsarray* customcomponentsseparatedbystring(id

self,sel

_cmd,nsstring *str)

//不起作用,求解釋

bool customisequaltostring(id

self,sel

_cmd,nsstring *str) {

printf

("真正起作用的是本函式customisequaltostring\r\n");

return

cfuncpointer2(self,_cmd, str);

}- (void) replacemethod

14、自動序列化**)

#import "nsobject+autoencodedecode.h"

@implementation nsobject (autoencodedecode)

- (void)encodewithcoder:(nscoder *)encoder

break;

default:

[encoder encodeobject:value

forkey:key];

break;}}

}free(ivars);

cls = class_getsuperclass(cls);}}

- (id)initwithcoder:(nscoder *)decoder

break;

default:

[self

setvalue:[decoder decodeobjectforkey:key]

forkey:key];

break;}}

}free(ivars);

cls = class_getsuperclass(cls);}}

returnself; }

IOS高階開發 Runtime(三)

11 系統類的方法實現部分替換 void methodexchange 列印結果 仔細看log 2013 07 26 16 33 22.776 highoc 7104 c07 sssaaaass 2013 07 26 16 33 22.778 highoc 7104 c07 sssaaaass 12...

IOS高階開發 Runtime(三)

11 系統類的方法實現部分替換 void methodexchange 列印結果 仔細看log 2013 07 26 16 33 22.776 highoc 7104 c07 sssaaaass 2013 07 26 16 33 22.778 highoc 7104 c07 sssaaaass 12...

IOS高階開發 Runtime(三)

11 系統類的方法實現部分替換 void methodexchange 列印結果 仔細看log 2013 07 26 16 33 22.776 highoc 7104 c07 sssaaaass 2013 07 26 16 33 22.778 highoc 7104 c07 sssaaaass 12...