I tried to answer Using a UITableView subclass with a UITableViewController with ISA Switching like so:
self.tableView->isa = [MyTableView class];
But, I get the compile error: Instance variable 'isa' is protected.
Is there a way to get around this? And, if so, is it safe to do?
I’m asking because @AmberStar’s answer to that question seems slightly flawed. (See my comment.)
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
object_setClass(tableView, [MyTableView class]).Please make sure this is really what you want.
Here is a small code-sample showing how this is a horrible idea.
and the output
As you can see the write to
storage->cwrote outside the memory allocated for the instance, and into the block I allocated for random. If that was another object, you just destroyed itsisapointer.