how to find location of Id in NSMutableArray

Fahim Parkar

I have NSMutableArray data as below.

(
        {
        Id = "-1";
        NameEn = Country;
    },
        {
        Id = 14;
        NameEn = Iran;
    },
        {
        Id = 11;
        NameEn = Jordan;
    },
        {
        Id = 5;
        NameEn = "United Arab Emirates";
    },
        {
        Id = 4;
        NameEn = "Suadi Arabia";
    },
        {
        Id = 3;
        NameEn = Kuwait;
    },
        {
        Id = 10;
        NameEn = Yemen;
    },
        {
        Id = 6;
        NameEn = Oman;
    },
        {
        Id = 12;
        NameEn = Syria;
    },
        {
        Id = 7;
        NameEn = Qatar;
    },
        {
        Id = 13;
        NameEn = Lebanon;
    },
        {
        Id = 1;
        NameEn = Egypt;
    },
        {
        Id = 8;
        NameEn = "Bahrain Kingdom";
    }
)

I want to find the location where Id=5.

Any idea how can I do?

I tried with below.

NSString *myCountry = [[NSUserDefaults standardUserDefaults] valueForKey:@"mCountryId"];
NSUInteger indexOfTheObject = [feedsCountry indexOfObject: myCountry];
NSLog(@"indexOfTheObject===%i==%@", indexOfTheObject, myCountry);

if (NSNotFound == indexOfTheObject) {
    NSLog(@"not found...");
}

But I get output as not found... for mCountryId as 5.

Nicolas Miari

Use an NSDictionary instead, and key your entries by Id; e.g.:

NSMutableDictionary* dictionary = [NSMutableDictionary new];

[dictionary setObject:@"Egypt" forKey:@"1"];
// (etc...)

EDIT: If you already have an array and can not change that, use a for loop like this:

for(NSDictionary* entry in givenArray){

    NSString* key = [entry objectForKey:@"Id"];
    NSString* value = [entry objectForKey:@"NameEn"];

    [dictionary setObject:value forKey:key];
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to find different object in NSMutableArray and add to another NSMutableArray?

From Dev

iOS: How to find insertion position in sorted NSMutableArray

From Dev

How to find the average of a group of NSNumbers from NSMutableArray?

From Dev

How to find location of installed library

From Dev

How to find a module's location

From Dev

How to find Private Key Location

From Dev

How to find location of installed library

From Dev

How to find all users that are in a location

From Dev

Find object by name in NSMutableArray

From Dev

How to addObject as NSMutableArray in NSMutableArray in swift

From Dev

How to find by foreign id?

From Dev

How to find location of third "_" in a string - JavaScript

From Dev

How to find nearest child to a click location?

From Dev

How to find location of link in Excel workbook?

From Dev

How to find the location of the rightmost black pixel

From Dev

How to find apc.php file location?

From Dev

How to find the location of _vimrc file in gvim on windows?

From Dev

How to find location based on IP address in Excel

From Dev

SQL Server: how to find closest location?

From Dev

How to find the new location of a repository after a rename

From Dev

How to find the location(s) of specific characters in a string

From Dev

How to find nearest location by latitude and longitude?

From Dev

How to find the current location index in the browser history

From Dev

How to to find location (ROI) of a recognized object in tensorflow

From Dev

How to find Realm file location of a Mac App

From Dev

How to find location of third "_" in a string - JavaScript

From Dev

How to find a router at an unknown location in a house?

From Dev

How to find current location of user in mkmapview

From Dev

How to find text on the screen and determine the location?

Related Related

  1. 1

    how to find different object in NSMutableArray and add to another NSMutableArray?

  2. 2

    iOS: How to find insertion position in sorted NSMutableArray

  3. 3

    How to find the average of a group of NSNumbers from NSMutableArray?

  4. 4

    How to find location of installed library

  5. 5

    How to find a module's location

  6. 6

    How to find Private Key Location

  7. 7

    How to find location of installed library

  8. 8

    How to find all users that are in a location

  9. 9

    Find object by name in NSMutableArray

  10. 10

    How to addObject as NSMutableArray in NSMutableArray in swift

  11. 11

    How to find by foreign id?

  12. 12

    How to find location of third "_" in a string - JavaScript

  13. 13

    How to find nearest child to a click location?

  14. 14

    How to find location of link in Excel workbook?

  15. 15

    How to find the location of the rightmost black pixel

  16. 16

    How to find apc.php file location?

  17. 17

    How to find the location of _vimrc file in gvim on windows?

  18. 18

    How to find location based on IP address in Excel

  19. 19

    SQL Server: how to find closest location?

  20. 20

    How to find the new location of a repository after a rename

  21. 21

    How to find the location(s) of specific characters in a string

  22. 22

    How to find nearest location by latitude and longitude?

  23. 23

    How to find the current location index in the browser history

  24. 24

    How to to find location (ROI) of a recognized object in tensorflow

  25. 25

    How to find Realm file location of a Mac App

  26. 26

    How to find location of third "_" in a string - JavaScript

  27. 27

    How to find a router at an unknown location in a house?

  28. 28

    How to find current location of user in mkmapview

  29. 29

    How to find text on the screen and determine the location?

HotTag

Archive