Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are class_setIvarLayout and class_getIvarLayout?

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?

like image 847
Bryan Chen Avatar asked Apr 21 '13 12:04

Bryan Chen


1 Answers

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.

like image 86
一二三 Avatar answered Sep 18 '22 21:09

一二三