Reputation: 15344
Background: I'm a .NET guy who has no prior experience in Objective-C/Cocoa, but I'm working through Aaron Hillegass' book, "Cocoa Programming for Mac OS X" trying to pick up the basics. (Great book so far, BTW!) For the purpose of completing one of the optional side challenges, I'm writing a document-based app that lets users draw ovals in arbitrary locations.
I have two classes, interfaces as follows:
@interface OvalDrawDocument : NSDocument
{
IBOutlet OvalView* myOvalView;
}
@end
@interface OvalView : NSView {
NSMutableArray *ovals;
}
@property (readwrite, assign) NSMutableArray *ovals;
@end
In the implementation of OvalDrawDocument
I'm trying to use the auto-generated property accessor for ovals
like so:
// in OvalView.m
@synthesize ovals;
// in OvalDrawDocument.m
[myOvalView setOvals:loadedOvals]; // setter?
NSMutableArray *ovalsToSave = [myOvalView ovals]; // getter?
However, the compiler warns me that the methods aren't found, and they don't work at runtime either. They appear in Code Sense, but I guess that doesn't really mean anything (Still getting used to the differences between XCode/VS here) I'm guessing there's some Obj-C concept I'm not quite grasping here, possibly related to the fact that myOvalView
is also an IBOutlet
, but I'm pretty lost. What should I be doing, and more importantly, why?
Update: I didn't declare OvalView.h in OvalDrawDocument.m. Doing so fixed the compilation warnings. However, saving and loading still don't seem to work and I can't figure out why.
As requested, I've posted the full source code online for perusal: Browse or Download (59KB zip).
Upvotes: 1
Views: 267
Reputation: 96363
The warning: Import OvalView's header in the OvalDrawDocumentation implementation file.
The messages not working at runtime: Make sure you have actually connected the outlet in IB.
Also, as Martin Pilkington said in his comment on your question, you probably should declare that property with retain
, not assign
.
Upvotes: 5
Reputation: 19782
I think you're going to have to show more of the code, since you appear to have the right things there, so you must be missing something somewhere else. Also, if you're going to declare ovals as a property, then it would make sense to use the property syntax in OvalDrawDocument:
// in OvalDrawDocument.m
myOvalView.ovals = loadedOvals; // setter
NSMutableArray *ovalsToSave = myOvalView.ovals; // getter
Upvotes: 0
Reputation: 951
It has nothing to do with the IBOutlet keywrod, which is simply a "helper" keyword for Interface Builder and is defined as "nothing" at compile time. You did import the relevant header files and did an alloc/init on myOvalView?
Upvotes: 1