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:
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.