众所周知,方法的区别不仅限于方法名,更重要的是参数及返回值类型,参数个数,OC中会将这些东西,typeEncoding后生成方法的描述types,用于运行时方法调用与传递中使用。
所谓typeEncoding,就是将返回值类型、目标对象、SEL、参数类型,encode后生成的一个简短字符集合,各类型对应的字符或字符集合,如下所示:
类型编码 typeEncode
{
BOOL = B;
CGFloat = d;
CGPoint = "{CGPoint=dd}";
CGRect = "{CGRect={CGPoint=dd}{CGSize=dd}}";
CGSize = "{CGSize=dd}";
CGVector = "{CGVector=dd}";
Class = "#";
NSInteger = q;
NSRange = "{_NSRange=QQ}";
SEL = ":";
block = "@?";
bool = B;
char = c;
double = d;
float = f;
id = "@";
"id*" = "^@";
int = i;
long = q;
"long long" = q;
short = s;
"size_t" = Q;
"unsigned int" = I;
"unsigned long" = Q;
"unsigned long long" = Q;
"unsigned short" = S;
void = v;
"void *" = "^v";
"void*" = "^v";
}
对应字节大小(x86_64 架构下):
{
BOOL = 1;
CGFloat = 8;
CGPoint = 16;
CGRect = 32;
CGSize = 16;
CGVector = 16;
Class = 8;
NSInteger = 8;
NSRange = 16;
SEL = 8;
bool = 1;
char = 1;
double = 8;
float = 4;
id = 8;
"id *" = 8;
int = 4;
long = 8;
"long long" = 8;
short = 2;
"size_t" = 8;
"unsigned int" = 4;
"unsigned long" = 8;
"unsigned long long" = 8;
"unsigned short" = 2;
void = 1;
"void *" = 8;
"void*" = 8;
}