Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If your tableview class provides ANY storage this will break. I would not recommend the path you're going down. But the correct method would be to use <code>object_setClass(tableView, [MyTableView class])</code>.</p> <p>Please make sure this is really what you want.</p> <p>Here is a small code-sample showing how this is a horrible idea.</p> <pre><code>#import &lt;objc/runtime.h&gt; @interface BaseClass : NSObject { int a; int b; } @end @implementation BaseClass @end @interface PlainSubclass : BaseClass @end @implementation PlainSubclass @end @interface StorageSubclass : BaseClass { @public int c; } @end @implementation StorageSubclass @end int main(int argc, char *argv[]) { BaseClass *base = [[BaseClass alloc] init]; int * random = (int*)malloc(sizeof(int)); NSLog(@"%@", base); object_setClass(base, [PlainSubclass class]); NSLog(@"%@", base); object_setClass(base, [StorageSubclass class]); NSLog(@"%@", base); StorageSubclass *storage = (id)base; storage-&gt;c = 0xDEADBEEF; NSLog(@"%X == %X", storage-&gt;c, *random); } </code></pre> <p>and the output</p> <pre><code>2011-12-14 16:52:54.886 Test[55081:707] &lt;BaseClass: 0x100114140&gt; 2011-12-14 16:52:54.889 Test[55081:707] &lt;PlainSubclass: 0x100114140&gt; 2011-12-14 16:52:54.890 Test[55081:707] &lt;StorageSubclass: 0x100114140&gt; 2011-12-14 16:52:54.890 Test[55081:707] DEADBEEF == DEADBEEF </code></pre> <p>As you can see the write to <code>storage-&gt;c</code> wrote outside the memory allocated for the instance, and into the block I allocated for random. If that was another object, you just destroyed its <code>isa</code> pointer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload