views:

46

answers:

1

Hello, I'm trying to detect when a verification code is entered into a text field, so like if I wanted someone to type in "this is a test.", it would then run the following code:

system("say this is a test");

But I keep getting the error "void value not ignored as it ought to be". I have no idea what this means. This is what I have so far, but I think I need some other help in which I'll explain below the code.

if ([SpecialCodeTextField setStringValue:[@"this is a test." stringValue]])
{
    system("say this is a test");
}

But if I did something on the iPhone SDK, I could do something like:

if (MyTextField.text = @"this is a test")
{
    [firstView setHidden:YES];
    [secondView setHidden:NO];
}

Or something like that. So what is * MyTextField.text = @"this is a test" * on the x86_64 architecture, or when programming for Mac? I'll do a little school equation for you here:

MyTextField.text = @"this is a test"; is to Changing textfield text on an iPhone

as

???????????????????????????? is to Changing textfield text on a Mac

+1  A: 

First of all take a look into the documentation of NSControl. In your first example you are messaging a NSControl to set a string value. (BTW. when you use the @"Whatever String" notation you implicitly create a static NSString object, so there is no need to call stringValue).

However, the documentation for -setStringValue: says that the message returns void, but your if structure expects any value to check.

In your second example, your code does two things. 1.) It assigns the text member of MyTextField @"this is a test". 2.) The if structure tests the text for nil.

What exactly do you want? If you want to check the NSTextField if its not nil, you would do something like this

if([specialCodeTextField stringValue]){
  ...
}

If you want to check if the textValue in your NSTextField contains "this is a test" you would do something like this:

if([[specialCodeTextField stringValue] isEqualToString:@"this is a test"]) {
  ...
}
thatsdisgusting
Wow that worked perfectly! Thank you so much!
Daniel Ricany