The following code is in my implementation file:
NSMutableArray *courseArray;
- (IBAction)btnClick:(id)sender
{
NSDictionary *courseNames;
if(![_txtBox.text isEqual:@""]) //if not empty
{
courseNames = [self retrieveCourseNamesForSemester:_txtBox.text];
for (NSString *key in courseNames)
{
NSString *val = [NSString stringWithFormat:@"%@-%@",key,[courseNames objectForKey:key]];
_txtView.text = val;
@try
{
[courseArray addObject:val];
}
@catch(NSException *e)
{
NSLog(@"Exception: %@ for value = %@", e, val);
}
}
}
[_coursePicker reloadAllComponents];
_coursePicker.hidden=false;
[_txtBox resignFirstResponder];
}
Where you see the call to NSLog(), I get the following error message:
2014-03-29 00:02:25.830 WebServiceTest[44646:60b] Exception: -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x8d82c30 for value = 73-522-Course Name
EDIT: Also, courseArray is populated with sample data in viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
courseArray = @[@"Australia (AUD)", @"China (CNY)",
@"France (EUR)", @"Great Britain (GBP)", @"Japan (JPY)"];
}
Is there somewhere I should be defining that courseArray will take NSString objects?
courseArrayis an immutable array. Where's your code that actually assigns a value to thecourseArrayvariable?courseArraywas defined asNSMutableArrayin the very first line of the code. How is it immutable?courseArrayis populated with sample data inviewDidLoad, adding to the question now.__NSArrayI- that's an internal representation for an immutable array (hence theI). If the error was about an actual mutable array, you would probably see__NSArrayM.