Re: Why the warnings or errors?
Re: Why the warnings or errors?
- Subject: Re: Why the warnings or errors?
- From: Kiel Gillard <email@hidden>
- Date: Tue, 20 Apr 2004 21:38:34 +1000
On 20/04/2004, at 9:27 PM, Gregory Weston wrote:
On Apr 20, 2004, at 6:35 AM, Kiel Gillard wrote:
I create a new project, name it "test" or something, open up the
mainmenu.nib file, I create two objects, namely "Controller" and
"AnotherObject." Then, I create an outlet in the object
"AnotherObject"
called "appController" of type "Controller." For the Controller, I
create an outlet titled "foo" of type "AnotherObject".
Quick terminology issue: What you created above were not objects; they
were classes. Objects are in the next sentence.
True
I then instantiate both these objects and link them up to eachother;
ie:
control drag a line from controller to another object and vice versa.
I then create files for each of my object I have created (Controller
and AnotherObject), wander off into Xcode and in the header for
Controller, I type
#import "Controller.h" in AnotherObject's header file (with the
#import
<Cocoa/Cocoa.h> line) and #import "AnotherObject.h" in the
Controller's
header file.
You could - maybe should - replace those imports with @class
declarations, and then import the headers within the .m files.
If I the hit Command R, it won't take it. 1 error - and it's either
'parse error before 'Controller'' or 'parse error before
'AnotherObject''. Ok, that's strange. I have no idea what it doesn't
like about that.
Neither does anyone else without seeing the code.
That's the thing - there is no code, it just pulls up on the line which
Interface Builder made when the files where created.
So being the person that I am, I do a hacky way around it and replace
"IBOutlet Controller * appController;" with "id appController;" and
similarly with the Controller.h file, replace "IBOutlet AnotherObject
*
foo;" with "IBOutlet id foo;" and what do you know? It damn well
works!
As it should. The Obj-C identifier 'id' is basically comparable to
'void*'; it's a generic object reference.
So when you start adding methods that are called from the other
object,
warnings start to pile up. You'll get messages near identical to
"cannot find method `-<method name>'; return type `id' assumed." Or at
least I do. But the methods still execute and return values, etc.
You can send any message to any object. Sounds like something's either
wrong with your import statements (unlikely) or with the headers
themselves.
If you are talking about declarations for the methods in the header
file, yes, the correct method defintions are there.
I'm concerned my tolerance for the now 25-odd warnings is a bad thing
and my naivety will come around and haunt me. If any of you have the
time, could you please point out what am I doing wrong (other than
using an id variable in the .h files)? Why does #import <a header file
of another object> cause the program not to compiler in the other
classes that need to use the object?
Did you really use <> instead of "" in your imports? If you did, the
preprocessor will skip your project directory when looking for the
headers.
< > was not used in my code at all. I was merely replacing the name of
the method in the error I used to test the problem with. So, if I wrote
a line that said #import <a header file>, I meant #import
"Controller.h", for example.
I shall try the @class directive.
Thank you
Kiel :-)
"Your friend is the person who knows all about you and still likes you."
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.