Removing <null> inside NSMutableDictionary inside NSMutableArray

I have been looking for some time how to remove nil, null, values โ€‹โ€‹here and in google, everything I saw is checked, but im always has an exception that says that the selector is incompatible. This is my array and NSMutableArray with NSMutableDictionary

Array Value = ( { "sub_desc" = "sub cat description of Laptop"; "sub_name" = Laptop; }, { "sub_desc" = "sub cat description of Printers"; "sub_name" = Printers; }, "<null>", "<null>", "<null>", "<null>" ) 

and im trying to remove values, any ideas?

my segue is as follows

 -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([segue.identifier isEqualToString:@"MySegue"]) { ChildTableViewController *myNextPage = [segue destinationViewController]; if ([myNextPage isKindOfClass:[ChildTableViewController class]]){ NSString *key = [[[parsedData listPopulated]objectAtIndex:self.tableView.indexPathForSelectedRow.row]valueForKey:@"name"]; myNextPage.childData = [[parsedData childPopulated]valueForKey:key]; } } } 

and childData is an NSMutableArray in my Child View controller, and childPopulated is an NSMutableArray, where Im inserts an NSMutableDictionary.

+4
source share
2 answers

Use [NSMutableArray removeObject:] :

Deletes all occurrences in the array of this object.

 NSMutableArray *array = ...; [array removeObject:@"<null>"]; 

Note: your array contains a combination of dictionary and string objects; not just vocabulary objects.

+4
source

This code should:

 NSMutableIndexSet *indexSet; for (NSUinteger i = 0; i < [array count]; i++) { if (![array[i] isKindOfClass:[NSNull class]]) { [indexSet addIndex:i] } } array = [array objectsAtIndexes:indexSet] 

If you want to delete objects that are a null string, then:

 NSMutableIndexSet *indexSet; for (NSUinteger i = 0; i < [array count]; i++) { if ([array[i] isKindOfClass:[NSString class]] && [array[i] isEqualToString:@"<null>") { [indexSet addIndex:i] } } [array removeObjectsAtIndexes:indexSet] 
+2
source

Source: https://habr.com/ru/post/1499813/


All Articles