views:

50

answers:

3

Hello!

I'm writing a program that will concatenate a string based on letters, and then check an array to see if that string exists. If it does, then it will print a line in IB saying so.

I've got all the ins-and-outs worked out, save for the fact that the simulator keeps crashing on me!

Here's the code:

-(IBAction)checkWord:(id)sender
{
NSMutableArray *wordList = [NSMutableArray arrayWithObjects:@"BIKE", @"BUS", @"BILL", nil];


if([wordList containsObject:theWord])
{
NSString *dummyText = [[NSString alloc] initWithFormat:@"%@ is a real word.", theWord];
checkText.text = dummyText;

[dummyText release];
}

}

"theWord" is the string that is being referenced against the Array to see if it matches an item contained within it. In this case "BIKE" is 'theWord'.

Thank you for your help in advance!

-MB

A: 

Here's what the console says:

2010-03-20 21:01:42.822 Button_fun[5563:207] *** -[__NSPlaceholderArray arrayWithObjects:]: unrecognized selector sent to instance 0x3906450
2010-03-20 21:01:42.823 Button_fun[5563:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray arrayWithObjects:]: unrecognized selector sent to instance 0x3906450'
2010-03-20 21:01:42.823 Button_fun[5563:207] Stack: (
29295707,
2547500297,
29677627,
29247094,
29099714,
12827,
2724869,
3132238,
3140975,
3136187,
2829791,
2738120,
2764897,
37391705,
29080448,
29076552,
37385749,
37385946,
2768815,
10484,
10338
)

And yes, the application automatically quits when the "Check Word" button is pressed.

MB
A: 

The variable "checkText" is a UILabel that is being linked 'dummyText'. It is defined as retain,nonatomic.

-(IBAction)checkWord:(id)sender
{
NSArray *wordList = [[NSArray alloc] initWithObjects: @"BIKE", @"BUS", @"BILL", nil];


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];
}

[wordList release];

}

I'm wondering if the containsObject is supposed to be a BOOL statement? If so, how would I phrase it?

Here is how checkText and theWord are defined in the header file for the project.

 @interface blah blah {
 IBOutlet UILabel *checkText;
 NSString *theWord;
 }
 @property (retain, nonatomic) UILabel *checkText;
 @property (retain, nonatomic) NSString *theWord;
 @end

This isn't the whole file, just a demonstration of how the variables are defined.

A: 

How have you defined your checkText property? As an NSString property, is it set to copy, and not retain?

P.S. Don't create answers to your own question to add in more information. Edit your original question instead.

Shaggy Frog