Reputation: 13842
Why can't I access properties of my class from within a C function? This is what I mean:
This is my code:
@interface MandelGenerator : NSWindow <NSWindowDelegate>
{
//Displays the image
IBOutlet JSImageView *imageView;
}
@end
/
#import "MandelGenerator.h"
@implementation MandelGenerator
void test(void) {
imageView = nil;
}
@end
Upvotes: 1
Views: 72
Reputation: 4805
A C function, unlike the instance method of a class, has no association with an Objective-C class. Just being in the same .m file as the class means nothing -- unlike an instance method, which is called on an instance by means of sending a message to it (thus providing the context necessary to know which imageView of all the imageViews that might exist as properties of instances of MandelGenerators), a C function isn't called on anything and can only "see" global variables and variables that are passed in to it as parameters. If you want this to work, you would need to change that C method to
void test(MandelGenerator* generator) {
generator.imageView = nil;
}
Assuming that imageView
is actually a property (it looks like an ivar to me).
Upvotes: 3