search element in NSDictionary nested in another NSDictionary

Dwight

Background:

a Object:

MyObject : NSObject
@property NSInteger type;

a NSDictionary:

@{
@"1":@{@"1":MyObject}
@"2":@{@"1":MyObject}
}

Now,got a MyObject and it's type=1; how to make sure whether this MyObject contained in the NSDictionary?

Misha

I'm taking into consideration, that your dictionary only has one key/pair and there are no similar key names present

  NSDictionary *dict = @{ @"a":@{@"c":@"MyObject"}                                        ,@"b":@{@"d":@"MyObject"} } ;

NSMutableArray *valuesArray = [[NSMutableArray alloc]init];
 // enumerate and add all values to our value array
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
    NSLog(@"Your value : %@", [obj description]);

    [valuesArray addObject:[[obj allValues] firstObject]];
}];

// check whether this value is present
if ([valuesArray containsObject:@"MyObject"]) {
    NSLog(@"My Object found",);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Obtain a NSArray of NSDictionary, from another one, with a subset of the original set of keys

From Dev

Extracting an NSDictionary from within another NSDictionary

From Dev

NSDictionary Search Time Complexity

From Dev

Finding keys/Values from nested NSDictionary

From Dev

AFNetworking POST method with nested NSDictionary

From Dev

Setting a value for a key in a nested NSDictionary error (immutable)

From Dev

NSDictionary to NSData and NSData to NSDictionary in Swift

From Dev

Search NSArray of NSDictionary using NSPredicate

From Dev

expected method to write dictionary element not found on object of type "NSDictionary *"

From Dev

Expected method to read array element not found on object of type NSDictionary*

From Dev

Obtain a NSArray of NSDictionary, from another one, with a subset of the original set of keys

From Dev

Sort NSDictionary

From Dev

Accessing NSDictionary of another ViewController shows null

From Dev

Extracting an NSDictionary from within another NSDictionary

From Dev

How do I gather JSON data nested in an array using NSDictionary

From Dev

Populate NSDictionary in tableview from a nested plist array (inside a dictionary)

From Dev

Use NSDictionary as other NSDictionary's key

From Dev

Error in adding an element to [String:Array<NSDictionary>] in Swift

From Dev

Add an element to NSDictionary from API response

From Dev

How to access to a NSdictionary element with reserved keyword?

From Dev

UITableview with NSArray contains NSDictionary and NSDictionary containg another NSDictionary

From Dev

[NSDictionary]!? is not convertible to [NSDictionary]?

From Dev

How to replace the NSDictionary value from another value in Objective C?

From Dev

Appending NSDictionary to [NSDictionary] gives unexpected results

From Dev

Search key value in NSDictionary array swift

From Dev

Initializing an NSDictionary

From Dev

NSDictionary to NSMutableArray

From Dev

How to get values nested within dictionary in NSDictionary?

From Dev

NSPredicate on nested array with NSDictionary as object

Related Related

  1. 1

    Obtain a NSArray of NSDictionary, from another one, with a subset of the original set of keys

  2. 2

    Extracting an NSDictionary from within another NSDictionary

  3. 3

    NSDictionary Search Time Complexity

  4. 4

    Finding keys/Values from nested NSDictionary

  5. 5

    AFNetworking POST method with nested NSDictionary

  6. 6

    Setting a value for a key in a nested NSDictionary error (immutable)

  7. 7

    NSDictionary to NSData and NSData to NSDictionary in Swift

  8. 8

    Search NSArray of NSDictionary using NSPredicate

  9. 9

    expected method to write dictionary element not found on object of type "NSDictionary *"

  10. 10

    Expected method to read array element not found on object of type NSDictionary*

  11. 11

    Obtain a NSArray of NSDictionary, from another one, with a subset of the original set of keys

  12. 12

    Sort NSDictionary

  13. 13

    Accessing NSDictionary of another ViewController shows null

  14. 14

    Extracting an NSDictionary from within another NSDictionary

  15. 15

    How do I gather JSON data nested in an array using NSDictionary

  16. 16

    Populate NSDictionary in tableview from a nested plist array (inside a dictionary)

  17. 17

    Use NSDictionary as other NSDictionary's key

  18. 18

    Error in adding an element to [String:Array<NSDictionary>] in Swift

  19. 19

    Add an element to NSDictionary from API response

  20. 20

    How to access to a NSdictionary element with reserved keyword?

  21. 21

    UITableview with NSArray contains NSDictionary and NSDictionary containg another NSDictionary

  22. 22

    [NSDictionary]!? is not convertible to [NSDictionary]?

  23. 23

    How to replace the NSDictionary value from another value in Objective C?

  24. 24

    Appending NSDictionary to [NSDictionary] gives unexpected results

  25. 25

    Search key value in NSDictionary array swift

  26. 26

    Initializing an NSDictionary

  27. 27

    NSDictionary to NSMutableArray

  28. 28

    How to get values nested within dictionary in NSDictionary?

  29. 29

    NSPredicate on nested array with NSDictionary as object

HotTag

Archive