views:

78

answers:

4
@property (nonatomic, retain)   NSMutableArray *filteredListContent;
----
@synthesize filteredListContent;


- (void)applicationDidFinishLaunching:(UIApplication *)application {     


    NSMutableArray *test = [[NSMutableArray alloc] init];
    [test addObject:@"test string"];
    [filteredListContent addObjectsFromArray:test];


    NSLog(@"%@", test);
    NSLog(@"Filtered Array is %@", filteredListContent);

    [window makeKeyAndVisible];
}

My Log for test shows 'test string' but 'Filtered list array is (null)'

How do I set the array 'filteredListContent' with the array test...

What am I doing wrong? :-(

A: 

You have to actually create filteredListContent, say with [[NSMutableArray alloc] init]. The error you are getting is that you are calling a method, -addObjectsFromArray:, on an object that is still nil: never created. As such, it just returns nil, and the list is never filtered.

chpwn
+2  A: 

Are you creating and initializing filtersListContent anywhere? Your code looks right, that should work.

You should also make sure to release your test variable, you have a memory leak here.

marcc
A: 

filteredListContent is a pointer to a NSMutableArray, it does not have any memory assigned to it, as a result you cannot call methods on it. The compiler does not generate an error because you are passing a message to nil which is perfectly alright.

A: 

Hi All,

Thanx for that.

so I changed the line...

[filteredListContent addObjectsFromArray:test];

to read...

filteredListContent = [NSMutableArray arrayWithArray:test];

This done it. I think I understand it now, though I declared it, I never created it...

Thanx.

Stef
What out for memory management problem. Check out http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html.
KennyTM
`$prevComment =~ s/^What/Watch/;`
KennyTM