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
First of all take a look into the documentation of
NSControl.In your first example you are messaging a
NSControlto set a string value.(BTW. when you use the
@"Whatever String"notation you implicitly create a staticNSStringobject, so there is no need to callstringValue).However, the documentation for
-setStringValue:says that the message returnsvoid,but your
ifstructure 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
NSTextFieldif its notnil, you would do something like thisIf you want to check if the
textValuein yourNSTextFieldcontains “this is a test” you would do something like this: