Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Problems with Classes

Problems with Classes
Thread Tools
goMac
Posting Junkie
Join Date: May 2001
Location: Portland, OR
Status: Offline
Reply With Quote
Jan 23, 2002, 01:33 AM
 
I created a Obj C++ Cocoa class in Project Builder (not a subclass in IB). Now I'm trying to link it together in code. My class is called TPKG2Class.

Heres the .h file for TPKG2Class:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
<font color = brown>//</font>
<font color = brown>// TPKG2Class.h</font>
<font color = brown>// duality4</font>
<font color = brown>//</font>
<font color = brown>// Created by Colin Cornaby on Tue Jan <font color = blue>22</font> <font color = blue>2002.</font></font>
<font color = brown>// Copyright (c) <font color = blue>2001</font> Conundrum Software. All rights reserved.</font>
<font color = brown>//</font>

#import &lt;Foundation/Foundation.h&gt;
#import &lt;Cocoa/Cocoa.h&gt;
#import &lt;PreferencePanes/NSPreferencePane.h&gt;


@interface TPKG2Class : NSObject {

}
- (void)TPKG2Name;
@end
</font>[/code]

Heres the .m for TPKG2Class:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
<font color = brown>//</font>
<font color = brown>// TPKG2Class.m</font>
<font color = brown>// duality4</font>
<font color = brown>//</font>
<font color = brown>// Created by Colin Cornaby on Tue Jan <font color = blue>22</font> <font color = blue>2002.</font></font>
<font color = brown>// Copyright (c) <font color = blue>2001</font> Conundrum Software. All rights reserved.</font>
<font color = brown>//</font>

#import <font color = red>"TPKG2Class.h"</font>


@implementation TPKG2Class
- (void)TPKG2Name
{
NSLog(<font color = orange>@"hi"</font>);
}
@end
</font>[/code]

I implement it in my main class with #import "interfacecontroller.h". When I try to call "[TPKG2Class TPKG2Name];" PB gives me two warnings:

interfacecontroller.m:46: warning: cannot find class (factory) method.
interfacecontroller.m:46: warning: return type for `TPKG2Name' defaults to id

Why? As far as I can tell, everything is right... :sigh:

BTW... How do I change the default software company name for the header at the top of the code? thanks.

--Colin Cornaby
8 Core 2.8 ghz Mac Pro/GF8800/2 23" Cinema Displays, 3.06 ghz Macbook Pro
Once you wanted revolution, now you're the institution, how's it feel to be the man?
     
amonitzer
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status: Offline
Reply With Quote
Jan 23, 2002, 07:51 AM
 
Is the checkbox next to the file in the project file listing checked? Otherwise it wouldn't be included in the compiled app.

Try cleaning the project and building again.
     
lindberg
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Jan 23, 2002, 04:13 PM
 
Nope, Project Builder is not the problem.

TPKG2Name is an instance method, yet in code you're calling it like a class method. The error message is correct; the compiler can not find the class method named "TPKG2Name".

If you change your declaration (and implementation) to be

+ (void)TPKG2Name;

then it will work (note the + instead of a -).

Alternatively, you could call it as an instance method:

TPKG2Class *anInstance;
anInstance = [[[TPKG2Class alloc] init] autorelease];
[anInstance TPKG2Name];
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:52 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,