Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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 regular
 
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
I'm new to mac...just wanted to know... IndyStarr Mac Basics and Help 13 Jun 18, 2009 04:31 PM
I Just Want To Know... WongJeezy99 Buying Tips and Advice 3 Jun 11, 2008 10:06 AM
I just want to know why.... dolphin1 Mac Basics and Help 13 Dec 13, 2006 08:42 PM
......all this talk of 1.4!! -- no, 1.2!! --no, 8.9!! -- i just want to know.... lemmon General Mac Discussion 15 Jun 1, 2002 09:16 AM
hey there, just wanted to know... How much ram is enough for osx? sevag1 Mac Help/Tips 51 Apr 23, 2002 09:42 PM


All times are GMT -5. The time now is 06:30 PM.

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

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