Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

addObject to NSMutableArray not working for iPhone App

There have been a few threads on this topic but none have been able to solve my problem. Essentially I am trying to add a custom object to an NSMutableArray and it doesn't seem to be adding. I don't get any errors but I get a warning saying that my array is an "unused variable" so it looks like it is not getting used. See code below. Any help is appreciated!

Here is the initialization in the app delegate (on run time it says this array is not being used):

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

Here is my object class organ.m (I am importing the app delegate, the rootviewcontroller and the organ.h file)

Organ *organObj = [[Organ alloc] initWithPrimaryKey:primaryKey];
organObj.organName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,1)];
organObj.isDirty = NO;

[appDelegate.organArray addObject: organObj];

[organObj release];

I know the organObj.organName is getting the correct values from my sqlite db because I can output them to the console. They just don't seem to be getting added to the array and the fact that it says the array is not being used means something is wrong.

Thanks in advance

like image 656
Mark Cicero Avatar asked Jul 14 '10 21:07

Mark Cicero


1 Answers

Just a guess but if organArray is intended to be a member of your app delegate, you are creating a new organArray when prefixing it with "NSMutableArray" so if I understand your code, change your app delegate to:

organArray = [[NSMutableArray alloc] init];

instead of:

NSMutableArray *organArray = [[NSMutableArray alloc] init];
like image 178
Dave B Avatar answered Sep 18 '22 20:09

Dave B