Search code examples
objective-cnsmutablearraynsarray

How get a key value in NSMutableArray?


A NSMutableArray called arrayDB, and it gets data from server by using AFNetworking, like this

  [self.arrayDB addObjectsFromArray:[responseObject objectForKey:@"list"]];
  NSLog(@"print:%@",self.arrayDB);

And the result like this.

  print:(
    {
    id = 10;
    key = 7707eca6ea4d2db923c8b7b4e6ec094c;
    },
    {
    id = 9;
    key = 7aaf962bc4df61a3b44c544c58fc6c82;
    },
    {
    id = 7;
    key = ce9d9e99a96d6417c6b34321c820c4c0;
    },
    {
    id = 6;
    key = 6086663465e5813d08f862eb443e2623;
    },
    {
    id = 4;
    key = 5d9519dd7de26f0139d6028fb83a4ead;
    }
   )

And now, I use sql statement to describe my needs, select key from arrayDB where id=10, how can I write in objective-C?


Solution

  • You can use NSPredicate like this:

    NSArray *myArray = [self.arrayDB filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(id == %@)", @"10"]];