美文网首页
Object-c type encodings类型编码

Object-c type encodings类型编码

作者: spyn_n | 来源:发表于2021-03-15 11:45 被阅读0次

为了和运行时系统协作,编译器将方法的返回类型和参数类型都编码成一个字符串,并和方法_cmd关联。我们可以通过给定一个类型,使用@encode() 编译指令来获得具体的编码。类型可以使基本类型,指针,结构体,联合体,类。

编码        含义

c                 A char

i                  An int

s                 A shot

l                 A long

q                A long long

C                   An unsigned char

I                 An unsigned int    

S               An unsigned short

L               An unsigned long

Q              An unsigned long long

f             A float

d              A double

B             C++ 标准的bool 或者  C99标准的 _Bool

v              A void

*             A character string (char *)

@             对象(无论是静态指定的还是通过id引用的)

#              类(class)

:              方法符号_cmd (SEL) 

?             A unknown type (其他时候,一般指函数指针)

[array type]      数组  eg:[12^f] 代表一个12个浮点数指针的数组

{name=type...}   结构体

eg:结构体

typedef struct example{

    id    anObject;

    char *aString;

    int anInt;

}Example;

编码是:{example=@*i}

(name=type...)    联合体

bnum        num 个bit的位域

^type        type类型的指针

注意:Object-C不支持long double类型,@encode(long double)和double一样,返回的字符串都是d


尽管有一些编码无法从@encode()的结果中直接得到,但是运行时系统会使用他们来表示协议类中方法的修饰符,如表


相关文章

  • Object-c type encodings类型编码

    为了和运行时系统协作,编译器将方法的返回类型和参数类型都编码成一个字符串,并和方法_cmd关联。我们可以通过给定一...

  • Type Encodings(类型编码)

    原文链接看这里!!! 为了帮助运行时系统更好地运行,编译器将方法的返回值和参数编码到一个字符串中,并将字符串与方法...

  • 类型编码(Type Encodings)

    https://developer.apple.com/library/mac/documentation/Coc...

  • 类型编码(Type Encodings)

    http://blog.csdn.net/iosswift/article/details/42361233 类型...

  • iOS 的Type Encodings

    iOS 的Type Encodings Type Encodings compiler 编码encode 每个me...

  • iOS 类型编码(Type Encodings)

    Type Encodings

  • Objective-C 类型编码

    一. Objective-C Type Encodings 编码意义cA chariAn intsA shortl...

  • Type Encodings

    Type Encodings Apple Type Encodings 就是编译器把 method 的参数列表和返...

  • Type Encodings

    为了帮助运行时系统,编译器将每个方法中的返回值类型和参数类型进行编码,并将方法名和方法选择器进行关联。编译器通过@...

  • Type Encodings

    @encode,@编译器指令 之一,返回一个给定类型编码为一种内部表示的字符串(例如,@encode(int) →...

网友评论

      本文标题:Object-c type encodings类型编码

      本文链接:https://www.haomeiwen.com/subject/jdckcltx.html