views:

91

answers:

1

Hi,

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

+9  A: 

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];
Dave B
Thank you! This worked and I can tell the object is being added to the array. I still have one issue though and it is that I am having trouble accessing the array from the RootViewController. A simple "return [appDelegate.organArray count]" in my numberOfRowsInSection method returns a 0. Does this have anything to do with the way I created my appDelegate object in my organ.m class? In my RootViewController.m file I have included organ.h and my delegate header file. Thanks again!
Mark Cicero
Never mind bud, I added the following line to my viewDidLoad method in my RootViewController and it fixed it:appDelegate = (RadiologyAppAppDelegate *)[[UIApplication sharedApplication] delegate];Thanks again!
Mark Cicero
@cicero19, Sorry I didn't see your question as I only occasionally visit this site. I'm glad you got it figured out!
Dave B