Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String Help - Objective C

I'm trying to make an app that will respond to your command when inserted. So you type in any text in the first box and press enter. It will respond with a response in the 2nd field. I'm not sure how the coding is done here. I'm having trouble with the "if inputbox text = @"whatever", I'm pretty sure that is completely off. Here is the code I have so far (not iphone sdk):

#import "HeliosControl.h"

@implementation HeliosControl
- (IBAction)quitButton:(NSButton *)sender {

}

- (IBAction)sendButton:(NSButton *)sender {

    if (inputBox *********)  // <------ What do I put in for the asterisks?
    {
        [outputBox setStringValue:@"Welcome to the SYSTEM"];
    }
    else
    {
        [outputBox setStringValue:@"I do not understand your command."];
    }

}
@end

BTW I'm a complete noob since I started Objective-C like a week ago.

Second Question:

This is a very simple one, but what would be the coding for closing an application? This is for my quit button.

like image 859
lab12 Avatar asked Aug 07 '26 20:08

lab12


1 Answers

You want if ([[inputBox stringValue] isEqualToString:@"whatever"]) (assuming inputBox is an NSTextField — otherwise, use the appropriate method for that class to get a string out of it).

Oh, and you can quit the application with [NSApp terminate:self].

like image 93
Chuck Avatar answered Aug 10 '26 15:08

Chuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!