object_setClass to bigger class

倾然丶 夕夏残阳落幕 提交于 2019-12-03 11:50:33

It could crash. As can be seen in the source code of the runtime here, it really just swaps the isa pointer.

If you really want to swap the isa to an isa of a subclass with more ivars, you should use class_createInstance with nonzero extraBytes.

Instead of using a larger subclass, use objc_setAssociatedObject and objc_getAssociatedObject to attach dynamically additional objects to your existing fixed-size object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!