Skip to content

Instantly share code, notes, and snippets.

@boredzo
Created March 6, 2013 12:21
Show Gist options
  • Select an option

  • Save boredzo/5098941 to your computer and use it in GitHub Desktop.

Select an option

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*.
#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