使用class_createInstance
官方文档里内容:
Creates an instance of a class, allocating memory for the class in the default malloc memory zone.
id class_createInstance(Class cls, size_t extraBytes)
Parameters
cls
The class that you wish to allocate an instance of.
extraBytes
An integer indicating the number of extra bytes to allocate. The additional bytes can be used to store additional instance variables beyond those defined in the class definition.
Return Value
An instance of the class cls.
使用class_createInstance
官方文档里内容:
Creates an instance of a class, allocating memory for the class in the default malloc memory zone.
id class_createInstance(Class cls, size_t extraBytes)
Parameters
cls
The class that you wish to allocate an instance of.
extraBytes
An integer indicating the number of extra bytes to allocate. The additional bytes can be used to store additional instance variables beyond those defined in the class definition.
Return Value
An instance of the class cls.
Declared In
runtime.h
参考资料
http://developer.apple.com/library/ma...
obj-c创建对象有两种方法
最近正在学习iPhone开发,书上说了嘛,objective-c是把实例化类的步骤分开来的,
alloc用来分配内存空间,然后再用init进行初始化或者用其他的方法,例如: