【Objective-C】类型编码及对应字节大小

众所周知,方法的区别不仅限于方法名,更重要的是参数及返回值类型,参数个数,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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值