8

I am trying to dynamic create objc class at runtime and I need to add some Ivar to the created class. I found class_addIvar which should do what I want, but I also found these functions:

  • class_setIvarLayout
  • class_getIvarLayout
  • class_getWeakIvarLayout
  • class_setWeakIvarLayout

the doc did not really said any useful information about these methods and I can't find out any useful explanation from web. So what are they? Do I need to use them if I want to do something with Ivar?

Bryan Chen
  • 45,816
  • 18
  • 112
  • 143

1 Answers1

9

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.

一二三
  • 21,059
  • 11
  • 65
  • 74