7

我正在尝试在运行时动态创建 objc 类,我需要Ivar在创建的类中添加一些。我发现class_addIvarwhich 应该做我想做的事,但我也发现了这些功能:

  • class_setIvarLayout
  • class_getIvarLayout
  • class_getWeakIvarLayout
  • class_setWeakIvarLayout

该文档并没有真正说明有关这些方法的任何有用信息,我也无法从网上找到任何有用的解释。那么它们是什么?如果我想做一些事情,我需要使用它们Ivar吗?

4

1 回答 1

8

The class_*IvarLayout methods are used by the garbage collector (if/when you're using it) to determine which areas of an object's memory need to be scanned for strong/weak references.

It's unlikely you'll ever need to call these methods; the appropriate layouts are generated when you call objc_registerClassPair.

于 2013-04-21T16:03:11.363 回答