So, I am new to Objective-C and I wrote a basic hello world program to get myself going and was able to do it without a problem. I have a textfield and a submit button and that changes the words to read "Hello, (name entered!)"
Here's my code for that:
What I want to do now is add a couple names where it will change the greeting. For example, if the name entered were Steve it would read "Hello, Steve, what kind of rapping name is Steve?"
So I would THINK (from other languages I know) the code would be:
And this compiles no problem but then says "Hello, Steve!" rather than what I want it to...
I also tried:
But no such luck...
I'm sure I'm just missing something stupid and basic, but I'm just trying to explore the language with basic (i.e. worthless) programming before getting serious and trying to write a program someone would actually want.
Thanks!
Here's my code for that:
Code:
-(void)clickbutton:(id)sender;
{
NSString *text = [ textField stringValue ] ;
if([ text length ] == 0) {
text = @"world";
}
NSString *text2 ;
text2 = [ NSString stringWithFormat: @"Hello, %@!" , text ] ;
[ label setStringValue : text2 ] ;
}
What I want to do now is add a couple names where it will change the greeting. For example, if the name entered were Steve it would read "Hello, Steve, what kind of rapping name is Steve?"
So I would THINK (from other languages I know) the code would be:
Code:
-(void)clickbutton:(id)sender;
{
NSString *text = [ textField stringValue ] ;
if([ text length ] == 0) {
text = @"world" ;
} else if (text == @"Steve") {
text = @"Steve, what kind of rapping name is Steve?" ;
}
NSString *text2 ;
text2 = [ NSString stringWithFormat: @"Hello, %@!" , text ] ;
[ label setStringValue : text2 ] ;
}
I also tried:
Code:
-(void)clickbutton:(id)sender;
{
NSString *text = [ textField stringValue ] ;
if([ text length ] == 0) {
text = @"world" ;
} else if ([ textField stringValue ] == @"Steve") {
text = @"Steve. What kind of rapping name is Steve?" ;
}
NSString *text2 ;
text2 = [ NSString stringWithFormat: @"Hello, %@!" , text ] ;
[ label setStringValue : text2 ] ;
}
But no such luck...
I'm sure I'm just missing something stupid and basic, but I'm just trying to explore the language with basic (i.e. worthless) programming before getting serious and trying to write a program someone would actually want.
Thanks!