Referencing an Array with Objects in iPhone SDK

Posted by user298261 on Stack Overflow See other posts from Stack Overflow or by user298261
Published on 2010-03-21T06:25:49Z Indexed on 2010/03/21 6:31 UTC
Read the original article Hit count: 373

Filed under:
|

Hello!

I was able to deduce my issue:

I'm having problem referencing a string with an object within an array.

Here's the code:

-(IBAction)checkWord:(id)sender
{

NSMutableArray *array = [[NSMutableArray alloc] init];

[array addObject:@"BIKE"];


NSString *dudeMan = theWord;

if([array containsObject:dudeMan])
{
    NSLog(@"Awesome!");
}

"theWord" is a String object that has been concatenated from 4 letters. It spells "BIKE", and I know this from a NSLog routine further up my code. However, for some reason, even though it spells BIKE, it will not reference correctly with the object within the array.

if I change the code to:

NSString *dudeMan = @"BIKE";

then the code will work.

If it is phrased as:

NSString *dudeMan = theWord;

Where 'theWord' is BIKE, then the program won't work.

Any ideas?

Thank you for your help!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about arrays