Created
March 6, 2013 12:21
-
-
Save boredzo/5098941 to your computer and use it in GitHub Desktop.
You can't access instance variables of an object from any code that is outside of the @implementation of that object's class. You can access those ivars anywhere within that @implementation—*even within a C function*.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| @class Foo; | |
| static int geti1(Foo *foo); | |
| static int geti2(Foo *foo); | |
| @interface Foo: NSObject | |
| @end | |
| int main(int argc, char *argv[]) { | |
| @autoreleasepool { | |
| Foo *foo = [Foo new]; | |
| NSLog(@"%d, %d", geti1(foo), geti2(foo)); | |
| } | |
| } | |
| @implementation Foo | |
| { | |
| int i; | |
| } | |
| static int geti1(Foo *foo) { | |
| return foo->i; | |
| } | |
| @end | |
| static int geti2(Foo *foo) { | |
| return foo->i; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment