Accessing an Objective-C ivar from outside the class at runtime <p>I know this idea completely breaks encapsulation, but say I have the following class extension:</p> <pre><code>@interface MyClass () { int reallyImportantIvar; } // ... @end </code></pre> <p>Normally, the class behaves like it should inside the Objective-C layer - sending and receiving messages, etc. However there is one ('public') subroutine where I need the best possible performance and very low latency, so I would prefer to use a C method. Of course, if I do, I can no longer access <em>reallyImportantIvar</em>, which is the key to my performance-critical task.</p> <p>It seems I have two options:</p> <ol> <li>Make the instance variable a static variable instead.</li> <li>Directly access the instance variable through the Objective-C runtime.</li> </ol> <p>My question is: is Option 2 even possible, and if so, what is its overhead? (E.g. Am I still looking at an O(n) algorithm to look up a class's instance variables anyway?)</p>