0

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?

markl
  • 7
  • 5

1 Answers1

0

You can use NSPredicate like this:

NSArray *myArray = [self.arrayDB filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(id == %@)", @"10"]];
Atanu Mondal
  • 1,714
  • 1
  • 24
  • 30
  • 1
    The id in dictionary is of number type so the predicate would be: `NSArray *myArray = [self.arrayDB filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(id == %@)", @(10)]];` – Bankim Mar 28 '18 at 09:57