Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTom Coomer
1,331 PointsIf statement not finding string
I have a problem with the following code:
myString = myTextField.text;
for (int i = 0; i < [array1 count]; i++) {
if (myString == array1[i]) {
myString = array2[i];
}
}
NSLog(myString);
This does not log anything however if I change "myString" to the code below, it does work. Any ideas?
myString = @"1";
for (int i = 0; i < [array1 count]; i++) {
if (myString == array1[i]) {
myString = array2[i];
}
}
NSLog(myString);
2 Answers
Stephen Goeddel
11,239 PointsTry using isEqualToString:
instead of == for your string comparison.
so:
if ([myString isEqualToString: array1[i]]) {
Joseph Potts
11,187 PointsMaybe try changing the NSLog statement to this:
NSLog(@"%@", myString);
Tom Coomer
1,331 PointsTom Coomer
1,331 PointsThat worked. It makes the change but once it has made the on the first word in the string however it does not continue to check the others. Do you know why this could be?