Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-26-2009, 08:57 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 39
Arcadiu is on a distinguished road
Default Why wont this work?

Ok dont laugh, I am practicing things I've learned from an Objective C book, and I have already struck an error declaring a class and trying to make a method which outputs to console saying Hello.

What happens is, it compiles but I get one error saying NSObject may not respond to -print

This is the code:

Code:
#import <Foundation/Foundation.h>

@interface Thing : NSObject
- (void) print;
@end

@implementation Thing : NSObject

- (void) print
{
	NSLog(@"Hello");
}

@end

int main() {
	
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	NSObject *Thing;
	Thing = [[NSObject alloc] init];
		
	
		
	
	
	[Thing print]; //NSObject may not respond to -print warning
	
	[Thing release];
	
	[pool drain];
	
	
	return 0;
}
Thanks in advance

Arc
__________________
Ultimate Pointer Website For Beginners (It Even Helped Me Understand)

http://www.cs.ucr.edu/~pdiloren/C++_Pointers/
Arcadiu is offline   Reply With Quote
Old 10-26-2009, 01:48 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 81
Jeepston is on a distinguished road
Default

replace
Code:
NSObject *Thing;

with
Code:
Thing *thing;
__________________
iPhone 2G 8Gb 3.1.2 JB, 3G 16Gb 3.1.2 JB, 3GS 16 Gb 3.1.2 JB
MB5,1 C2D 2GHz 2GB RAM
Mac OS X 10.5.8
Jeepston is offline   Reply With Quote
Old 10-26-2009, 01:59 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 39
Arcadiu is on a distinguished road
Default

Is that because I am making an instance variable of the object Thing?

Can you explain why and whats wrong with NSObject *Thing;?
__________________
Ultimate Pointer Website For Beginners (It Even Helped Me Understand)

http://www.cs.ucr.edu/~pdiloren/C++_Pointers/
Arcadiu is offline   Reply With Quote
Old 10-26-2009, 02:10 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 81
Jeepston is on a distinguished road
Default

because you are declaring an object of class NSObject, which doesn't have method "print".

To introduce "print", you create new class Thing which inherits class NSObject and create this method. So now all objects of class Thing (and derivative classes) will have method "print".
__________________
iPhone 2G 8Gb 3.1.2 JB, 3G 16Gb 3.1.2 JB, 3GS 16 Gb 3.1.2 JB
MB5,1 C2D 2GHz 2GB RAM
Mac OS X 10.5.8
Jeepston is offline   Reply With Quote
Old 10-27-2009, 01:42 PM   #5 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 39
Arcadiu is on a distinguished road
Default

This still wont work.

Could someone write me a program like that that outputs hello in nslog and to run that method you need to call it from main?

also could it include interface and implementation with a object name of your choice

sorry if this seems off topic but i am really stumped and is really getting my head down low that i cant output hello to terminal ...
__________________
Ultimate Pointer Website For Beginners (It Even Helped Me Understand)

http://www.cs.ucr.edu/~pdiloren/C++_Pointers/
Arcadiu is offline   Reply With Quote
Old 10-27-2009, 01:51 PM   #6 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 81
Jeepston is on a distinguished road
Default

wait a minute... what terminal do you mean? debug console in xcode or console of the jailbroken iphone?
__________________
iPhone 2G 8Gb 3.1.2 JB, 3G 16Gb 3.1.2 JB, 3GS 16 Gb 3.1.2 JB
MB5,1 C2D 2GHz 2GB RAM
Mac OS X 10.5.8
Jeepston is offline   Reply With Quote
Old 10-27-2009, 02:53 PM   #7 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 39
Arcadiu is on a distinguished road
Default

the Terminal console on the macbook :S if that makes any sense

its not on a iphone i dont have an ipod touch/iphone
__________________
Ultimate Pointer Website For Beginners (It Even Helped Me Understand)

http://www.cs.ucr.edu/~pdiloren/C++_Pointers/
Arcadiu is offline   Reply With Quote
Old 10-27-2009, 03:16 PM   #8 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 81
Jeepston is on a distinguished road
Default

darn, I confused this forum with iphone development %)
__________________
iPhone 2G 8Gb 3.1.2 JB, 3G 16Gb 3.1.2 JB, 3GS 16 Gb 3.1.2 JB
MB5,1 C2D 2GHz 2GB RAM
Mac OS X 10.5.8
Jeepston is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting 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
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 464
12 members and 452 guests
Domele, Duncan C, Feldspar, MacBook MH, Objective Zero, patapple, peterwilli, pipposanta, Punkjumper, SLIC, taylor202, Today's Posts
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,694
Threads: 94,137
Posts: 402,950
Top Poster: BrianSlick (7,990)
Welcome to our newest member, peterwilli
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:04 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0