Re: Can't import a header file? + other warnings
Re: Can't import a header file? + other warnings
- Subject: Re: Can't import a header file? + other warnings
- From: Nicholas Riley <email@hidden>
- Date: Tue, 30 Apr 2002 11:59:26 -0500
- Mail-followup-to: Joel Rosenblum <email@hidden>, email@hidden
On Tue, Apr 30, 2002 at 02:34:54AM -0400, Joel Rosenblum wrote:
>
I downloaded the MOKit from lorax.com for its RegEx capabilities, and I
>
installed it by dragging the MOKit.framework folder to my
>
/Library/Frameworks folder, as the Installation Guide told me to. Then,
>
in the class where I used the RegEx, at the top I put #import "MOKit.h"
>
but when I built the app, I got a compiler error saying it couldn't find
>
MOKit.h. Well, I don't know why it can't find it. Is it in the wrong
>
folder? I tried going to Project:Add Frameworks and adding
>
MOKit.framework manually. That didn't fix the problem though, it still
>
can't find MOKit.h. Any suggestions?
#import <MOKit/MOKit.h>. You need to tell the compiler/preprocessor
to look inside the framework.
>
Also, I'm getting a number of other compiler warnings which I don't
>
understand:
>
WindowController.m:11: warning: cannot find method.
>
WindowController.m:11: warning: return type for `setController:'
>
defaults to id
>
WindowController.m:12: warning: cannot find method.
>
WindowController.m:12: warning: return type for `startAnimating'
>
defaults to id
>
>
It says it can't find the method, but then it says the return type for
>
that SAME method (which it says it can't find!) defaults to id. I don't
>
know why it would default to id, since I know that the return type is
>
void. And even though it can't find the method, I'm fairly certain (by
>
use of a beep) that the method IS being called! At least one of them is.
>
startAnimating is a method that should be in NSProgressIndicator, no?
Right. Objective-C doesn't need the declaration of a method in order
to compile a message, just as C doesn't need the declaration of a
zero-argument function in order to compile a call to it. The only
thing the 'defaults to id' message is telling you is that
Objective-C's default method return type is id (following Smalltalk
which doesn't have return type declarations, although I don't think
ObjC will automatically return self the way Smalltalk does). In fact,
when declaring method you can leave off the 'id':
- init;
{
return [super init];
}
(not that that's particularly useful, but... :-)
So, the warnings above are just the equivalent of:
blah.c:3: warning: implicit declaration of function `bleh'
The reason why startAnimating is not defined is likely that you have
only imported Foundation headers, not Application Kit headers - and
NSProgressIndicator is defined in the AppKit. Make sure you have:
#import <AppKit/AppKit.h>
or
#import <Cocoa/Cocoa.h>
at the top of your .m file, not just <Foundation/Foundation.h>.
>
This is a line of code I have to format a string, the compiler says
>
"class factory method not found" referring to "makeStringWithFormat" no
>
doubt. I must have gotten the syntax wrong, because I don't see the
>
whole declaration in the Cocoa help.
>
>
result = [NSString makeStringWithFormat:@"%f words/min, %f
>
%f-letter-words/min.", f1, f2, f3];
>
>
And then it says the return type for makeStringWithFormat defaults to
>
id. Argh!
Right, it's -[NSString stringWithFormat]. Almost all convenience
constructors in Cocoa are named like this, +[NSFoo fooWithBar: ...] -
just as the equivalent init methods are named as -[NSFoo initWithBar:
...].
Project Builder provides some useful features for completing symbol
names, if your project is indexed. So, you can start typing 'NSString
string', Command-double-click on the 'string', and it'll pop up a menu
with all the indexed methods that begin with 'string'. Because of the
convention above, these include all the convenience constructors of
NSString. Select an item and you'll go to the header file where that
method is defined. Use Option-double-click instead, and you'll get
the HTML documentation for that method.
>
I made an outlet in IB from one class to another, and connected it in
>
the instance of the containing class, all in IB. I of course did "Create
>
Files" from the class. The outlet did not work though, as I was unable
>
to call any of the outlet's methods in code. What might cause the outlet
>
to not work? All of my other outlets work.
Make sure you are calling the method on the instance of the object
that you've defined in IB. Outlets are just instance variables whose
values are set as the objects are unarchived from the nib, so you can
do something like:
- (void)awakeFromNib;
{
NSLog(@"%@ outlet xxx is %@", self, myOutletName);
}
to see if the outlet is being correctly hooked up.
Another possibility is that you're getting caught with key-value
coding. If you have an outlet named foo and an instance method named
setFoo:, foo:, _setFoo:, and a few others which I'm forgetting (see
the NSKeyValueCoding docs) then the unarchiver will prefer the method
to the instance variable and, instead of setting the variable
directly, will call the method with the object as a parameter, instead.
>
Where is setVisible:BOOL for controls in the cocoa documentation?
It doesn't exist. You need to remove the view from its superview,
retain it, and add it back later. Please search the list archives for
code examples, etc., as this has come up several times in the past.
(
http://cocoa.mamasam.com indexes both the Apple and Omni Cocoa
lists).
>
How do I set the text of an editfield? I tried setText but that didn't
>
work, the docs don't seem to mention any way of setting the text for an
>
NSTextField. Such an elementary function, too...
setStringValue:. Always check the superclasses of a class, in this
case it's defined in NSControl.
>
What is the Ticks function in cocoa? I thought NSTicks() would return
>
the tick count of the system, but that function doesn't seem to exist.
>
And where would I search the docs for this?
This was discussed in the past few days on this list. Please search
the archives.
If you're asking questions at this level, you might be better off with
a Cocoa tutorial book, otherwise you'll write a lot of messy code with
mistaken assumptions and regret it later. :-) (I remember looking
back at my first Java code where I did things like 'String xyz = new
String("abc")' and cringing.) Bill Bumgarner posted a long and
detailed message on getting started with Cocoa a few days ago,
including book and Web site suggestions. He also copied it to his
Weblog:
<
http://radio.weblogs.com/0100490/2002/04/27.html#a185>
and it makes for some good reading.
--
=Nicholas Riley <email@hidden> | <
http://www.uiuc.edu/ph/www/njriley>
Pablo Research Group, Department of Computer Science and
Medical Scholars Program, University of Illinois at Urbana-Champaign
_______________________________________________
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.