alloc底层探索第一步,先去苹果开发者上下载一份 objc-750源码
根据源码可以看到alloc完整的流程图,如上图
alloc是系统给对象分配内存空间,init是给对象进行实例化
最后
// Use raw pointer isa on the assumption that they might be
// doing something weird with the zone or RR.
obj->initIsa(cls);
返回类的实例对象
init的底层
id
_objc_rootInit(id obj)
{
// In practice, it will be hard to rely on this function.
// Many classes do not properly chain -init calls.
return obj;
}
返回自己,什么都没有做啊,工厂模式是为了subClass 重写 初始化赋值
网友评论