user3001526
user3001526

Reputation: 81

Removing object from array doesnt remove anything

I have:

self.path = [self pathByCopyingFile:@"Notes List.plist"];
self.data = [[NSMutableDictionary alloc] initWithContentsOfFile:self.path];
self.notes = [self.data objectForKey:@"Notes"];

Then in a button (Button method definitely gets called):

NSString *title = self.navigationItem.title;
         //Filter notes array by title
         NSPredicate *pred = [NSPredicate predicateWithFormat:@"Title =[cd] %@", title];
         NSArray * titleArray = [self.notes filteredArrayUsingPredicate:pred];

         //delete all the notes with the old title name
         [self.notes removeObject:titleArray];
         NSLog(@"%@", self.notes);

At this point, self.notes still contains the items and i dont know why they arnt being removed

Upvotes: 0

Views: 75

Answers (1)

rmaddy
rmaddy

Reputation: 318774

You are trying to remove an array from the array. That's not what you want. I believe your goal is to remove all of the objects in the titleArray from your notes array.

And this doesn't even consider that self.notes is probably an NSArray and not an NSMutableArray.

If self.notes is mutable you can use the removeObjectsInArray:.

[self.notes removeObjectsInArray:titleArray];

Upvotes: 3

Related Questions