ios筆記 runtime Method詳解

2021-07-10 17:53:08 字數 2661 閱讀 2135

runtime method 介紹:
method型別是乙個objc_method結構體指標,objc_method有三個成員

typedef struct objc_method method;

struct objc_method

// 函式呼叫,但是不接收返回值型別為結構體

method_invoke

// 函式呼叫,但是接收返回值型別為結構體

method_invoke_stret

// 獲取函式名

method_getname

// 獲取函式實現imp

method_getimplementation

// 獲取函式type encoding ,其結果是一串值

method_gettypeencoding

// 複製返回值型別

method_copyreturntype

// 複製引數型別

method_copyargumenttype

// 獲取返回值型別

method_getreturntype

// 獲取引數個數

method_getnumberofarguments

// 獲取函式引數型別

method_getargumenttype

// 獲取函式描述

method_getdescription

// 設定函式實現imp

method_setimplementation

// 交換函式的實現imp

method_exchangeimplementations

void *memset(void *s, int ch, size_t n);

函式解釋:將s中前n個位元組 (typedef unsigned int size_t )用 ch 替換並返回 s 。

memset:作用是在一段記憶體塊中填充某個給定的值,它是對較大的結構體或陣列進行清零操作的一種最快方法[1]  

- (void)getallmethods{

//獲取所有方法

unsigned int outcount = 0;

method *methods = class_copymethodlist([self class], &outcount);

for (int i = 0; i

method_invoke的介紹

method method = class_getinstancemethod([viewcontroller class], nsselectorfromstring(@"getallmethods"));

method_invoke([viewcontroller class], method);

<===> ((void (*)(id,sel))objc_msgsend)((id)self,nsselectorfromstring(@"getallmethods"));

//列印結果

2016-03-25 13:20:11.598 runtimemethoddemo[1610:187967] 方法名:getallmethods

2016-03-25 13:20:11.600 runtimemethoddemo[1610:187967] 引數型別:@

2016-03-25 13:20:11.600 runtimemethoddemo[1610:187967] 引數型別::

2016-03-25 13:20:11.600 runtimemethoddemo[1610:187967] 返回型別值型別:v

2016-03-25 13:20:11.601 runtimemethoddemo[1610:187967] 返回型別輸入引數混合編碼:v16@0:8

2016-03-25 13:20:11.601 runtimemethoddemo[1610:187967] 方法名:setvc:

2016-03-25 13:20:11.601 runtimemethoddemo[1610:187967] 引數型別:@

2016-03-25 13:20:11.601 runtimemethoddemo[1610:187967] 引數型別::

2016-03-25 13:20:11.602 runtimemethoddemo[1610:187967] 引數型別:@

2016-03-25 13:20:11.602 runtimemethoddemo[1610:187967] 返回型別值型別:v

2016-03-25 13:20:11.602 runtimemethoddemo[1610:187967] 返回型別輸入引數混合編碼:v24@0:8@16

2016-03-25 13:20:11.602 runtimemethoddemo[1610:187967] 方法名:noretnoarg

2016-03-25 13:20:11.602 runtimemethoddemo[1610:187967] 引數型別:@

2016-03-25 13:20:11.603 runtimemethoddemo[1610:187967] 引數型別::

2016-03-25 13:20:11.603 runtimemethoddemo[1610:187967] 返回型別值型別:v

2016-03-25 13:20:11.605 runtimemethoddemo[1610:187967] 返回型別輸入引數混合編碼:v16@0:8

ios筆記 ARC筆記

arc知識介紹 1 概念 arc的全稱是 automatic reference counting 自動引用計數 是自ios5 之後增加的新特性,編譯器會自動在合適的地方插入適當的retain release autorelease 語句,會自動生成記憶體管理的 不用程式設計師手動編寫。2 如果是手...

IOS學習筆記

uiview beginanimations view flip context nil 設定動畫塊 uiview setanimationduration 1.25 動畫時間 uiview setanimationcurve uiviewanimationcurveeaseinout 動畫曲線 u...

ios學習筆記

actionsheet 標頭檔案裡加協議。ibaction buttonpressed id sender void actionsheet uiactionsheet actionsheet diddismisswithbuttonindex nsinteger buttonindex 從plis...