Obj-C Core Question: Object Call Methods

Background: I'm a .NET guy with no experience in Objective-C / Cocoa, but I'm working on Aaron Hilllegass's book, Cocoa Programming for Mac OS X, trying to pick the basics. (Great book so far, BTW!) To accomplish one of the additional tasks, I am writing a document-based application that allows users to draw ovals in arbitrary locations.

I have two classes, interfaces:

@interface OvalDrawDocument : NSDocument
{
    IBOutlet OvalView* myOvalView;
}
@end

@interface OvalView : NSView {
    NSMutableArray *ovals;
}
@property (readwrite, assign) NSMutableArray *ovals;
@end

      

In implementation, OvalDrawDocument

I'm trying to use an autogenerated property accessor for the ovals

following:

// in OvalView.m
@synthesize ovals;

// in OvalDrawDocument.m
[myOvalView setOvals:loadedOvals];                // setter?
NSMutableArray *ovalsToSave = [myOvalView ovals]; // getter?

      

However, the compiler warns me that no methods were found and they also fail at runtime. They show up in Code Sense, but I'm guessing it doesn't really mean anything (still used to the differences between XCode / VS here). I am guessing that some Obj-C concepts that I do not fully understand may be related to the fact that myOvalView

it is IBOutlet

, but I am rather lost. What should I do, and more importantly, why?


Update : I have not declared OvalView.h in OvalDrawDocument.m. This fixed compilation warnings. However, saving and loading still doesn't work and I can't figure out why.

As requested, I have posted the full source code online for reading: Browse or Download (59KB zip) .

+1


a source to share


3 answers


Warning: import the OvalView header in the OvalDrawDocumentation implementation file.

Messages not working at runtime: Make sure you have actually plugged in the socket in the IB.



Also, as Martin Pilkington said in his comment to your question, you should probably declare this property with retain

, not assign

.

+5


a source


This has nothing to do with keywrod IBOutlet, which is just a "helper" keyword for Interface Builder and is defined as "nothing" at compile time. Have you imported the appropriate header files and ran the alloc / init command in myOvalView?



+1


a source


I think you will need to show more code as you seem to have the right things, so you must be missing something else. Also, if you are going to declare ovals as a property, then it makes sense to use the property syntax in OvalDrawDocument:

// in OvalDrawDocument.m
myOvalView.ovals = loadedOvals;                // setter
NSMutableArray *ovalsToSave = myOvalView.ovals; // getter

      

0


a source







All Articles