1
@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? :-(

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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.

Comments

-1

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.

2 Comments

What out for memory management problem. Check out developer.apple.com/mac/library/documentation/cocoa/Conceptual/….
$prevComment =~ s/^What/Watch/;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.