if([wordList containsObject: theWord])
{
NSString *dummyText = [[NSString alloc] initWithFormat:@"%@ is a real word.", theWord];
checkText.text = dummyText;
[dummyText release];
}
else{
NSString *dummyText = [[NSString alloc] initWithFormat:@"%@ is not a real word.", theWord];
checkText.text = dummyText;
NSLog(@"NOT A WORD");
[dummyText release];
}
}
The variable "theWord" equals BIKE, in this instance, and it's meant to be compared to the array so that the "if" statement executes.
"checkText" is a label on IB, it is currently empty, but should display the text within the "if" statement.
"wordList" is another array already defined in the header file.
I've looked at my header file, but everything is as it should be.
if([wordList containsObject: theWord])
{
NSString *dummyText = [[NSString alloc] initWithFormat:@"%@ is a real word.", theWord];
checkText.text = dummyText;
[dummyText release];
}
else{
NSString *dummyText = [[NSString alloc] initWithFormat:@"%@ is not a real word.", theWord];
checkText.text = dummyText;
NSLog(@"NOT A WORD");
[dummyText release];
}
}
The variable "theWord" equals BIKE, in this instance, and it's meant to be compared to the array so that the "if" statement executes.
"checkText" is a label on IB, it is currently empty, but should display the text within the "if" statement.
"wordList" is another array already defined in the header file.
I've looked at my header file, but everything is as it should be.
Thank you for your help in advance!
-SS
Your approach cannot work because containsObject checks if the string object ITSELF is contained (i.e. the same pointer). You can add multiple identical string objects to an array.
If you were to use an NSSet instead then you would be more in luck because NSSet differentiates objects by hash and thus would be able to respond with YES to a containsObject there.
__________________
regards
Oliver Drobnik Cocoanetics - Our DNA is programmed in Objective-C.
Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Probably not the best example then, but in my experience, it will work however you create the NSString.
The way sunnystormy is doing it should be working.
EDIT: Replicating your code exactly gives the desired results. You might want to check that "theWord" has not been autoreleased.
Harry, you are right. RTFM'ing, I found this:
Quote:
This method determines whether anObject is present in the receiver by sending an isEqual: message to each of the receiver’s objects (and passing anObject as the parameter to each isEqual: message).
__________________
regards
Oliver Drobnik Cocoanetics - Our DNA is programmed in Objective-C.
Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!