Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 1, 2011, 12:06 PM   #1
Abunga
macrumors newbie
 
Join Date: Jan 2011
Almost got it, just want to know this.

Hello again, my knowledge is rapidly improving but i have come stuck with this problem.

I have created a small app, just for practice, that will compare the answer given my a user in a text field with a set word. This is for a single on screen anagram. Should the user put in 'LITTLE', it will say WRONG! and should they put in 'DANGEROUS', it will of course say CORRECT! My issue is that I have tried different formations to no avail. It wont use the 'compare' operation with a text field.

What might you suggest. The offending code is below.

Thanks, Abunga.

Code:
#import "Text_PracticeViewController.h"

@implementation Text_PracticeViewController


@synthesize userInput;
@synthesize userMark;
@synthesize userCorrect;

-(IBAction) setOutput:(id)sender {
	if (userInput=@"DANGEROUS") {
		userCorrect.text=@"CORRECT!";
	} else {
		userCorrect.text=@"WRONG!";
}
		
}
__________________
If you're the PC, I'm happy to be the Mac!
(Apple Imac 21.5" / Iphone 3GS/ HP Mini 210 Netbook)
Abunga is offline   0 Reply With Quote
Old Feb 1, 2011, 12:14 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
First, = is not a compare operator. == is the equality comparison.

Second, never use == to compare strings for equality. There is an NSString method for this purpose. Consult the NSString reference doc, and search for the term equal. You should see several methods. Read the descriptions before choosing the correct one.

Third, since you didn't show what type userInput is, you may have to use one of its properties that is an NSString, rather than the userInput variable itself. We could guess that userInput is some kind of UI text field, but we'd just be guessing, which is a poor way to debug anything.
chown33 is offline   0 Reply With Quote
Old Feb 1, 2011, 03:09 PM   #3
cnstoll
macrumors 6502
 
Join Date: Aug 2010
Just a further note.

The reason you never use "==" to compare Objects (such as an instance of NSString, or UITextField) is that "==" will compare the values of the pointers, not the values the Objects contain. Always use comparison methods to compare the values of Objects.
cnstoll is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 11:10 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC