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

View Single Post
Old 05-07-2009, 04:31 AM   #1 (permalink)
carbcycle
New Member
 
Join Date: May 2009
Posts: 3
carbcycle is on a distinguished road
Question Declaring a string variable

Hi,

I'm just starting to learn Objective-C.........very simple question for you...

How do I declare a string variable?

At the moment I am using:

Code:
NSString *colour;
But when I go to printf the contents of this variable, nothing is displayed.

I'm writing a small program to try and understand the syntax in objective-c, so please forgive my immaturity in the code below:-

Code:
#import <Cocoa/Cocoa.h>
#import <stdio.h>


@interface Cup : NSObject
{
	BOOL empty1;
	NSString *colour;
}

-(void)drinkCup:(BOOL)done;
-(void)paintCup:(id)paint;
-(void)print;

@end

@implementation Cup

-(void)drinkCup:(BOOL)done

{

	empty1 = done;
	
}

-(void)paintCup:(id)paint
{

	colour = paint;
	
}

-(void)print

{

	printf("The cup has been drunk:%i\n", empty1 );
	printf("The cup colour is:%@", colour );
	
	
}



@end


int main(int argc, char *argv[])
{
	Cup *lukesCup = [[Cup alloc] init];
	
	[lukesCup drinkCup: 1];
	[lukesCup paintCup: @"Red"];
	[lukesCup print];
	
	[lukesCup release];
	
    return NSApplicationMain(argc,  (const char **) argv);
	
}
Do I need to init the string as it is based on the class NSString?

Thanks for your help.
carbcycle is offline   Reply With Quote
 

» Advertisements
» Online Users: 443
18 members and 425 guests
13dario13, 7twenty7, baja_yu, bhsu21, Bryan1, ClerurcifeDer, Duncan C, gdogdev, guusleijsten, HowEver, iAppDeveloper, iekei, ilmman, Paul Slocum, PavelMik, QuantumDoja, stanny, yys
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,637
Threads: 94,101
Posts: 402,822
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jessicagx69
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:21 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.