NSMutableArray + Retrival

Discussion in 'Mac Programming' started by semaja2, Jan 31, 2007.

  1. semaja2 macrumors 6502a

    Dec 12, 2005
    Hi guys,

    I am working on my first OBJ-C project but i have stumbled across a problem when trying to retrive the actual text thats being stored in a NSMutableArray

    What i need to be able to do is find with in the "SSID" object the name of the SSID i have in a variable, then with that found i need to be able to grab the connectSourceScript that it has in another object...

    this what i have so far, but it wont work really at all due to i cant work out how to match the SSIDs
    				script = [[ssidDic objectAtIndex:0] objectForKey:@"connectSource"];
    				/*only partly works result = ("display dialog hello", "--disconnect ScriptCode") */
    				script = [ssidDic valueForKey:@"disconnectSource"];
    i hope this makes senses
  2. kainjow Moderator emeritus


    Jun 15, 2000
    Arrays in Cocoa hold objects. If it holds NSString objects, then you go through each item in the array and check to see if the string is equal to a string variable you have somewhere.

    If you're just trying to modify a project, post some more code. If you're trying to build something from scratch, I'd suggest reading up more on Cocoa. This is basic stuff that is probably covered in the beginning of any Cocoa book.
  3. HiRez macrumors 603


    Jan 6, 2004
    Western US
    Just a general tip, if you're comparing strings for equality of content, don't use if aString == anotherString, use if ([aString isEqualToString:anotherString]).
  4. caveman_uk Guest


    Feb 17, 2003
    Hitchin, Herts, UK
    Because the first one compares the object memory address i.e are the two variables pointing at the exact same object. The second compares the contents of the objects i.e. are the characters the same.
  5. whooleytoo macrumors 604


    Aug 2, 2002
    Cork, Ireland.
    There isn't enough in this snippet to see how you're storing your data, but it looks like you're trying to store name, value pairs.

    If so, you might consider using NSMutableDictionary instead of NSMutableArray.
  6. semaja2 thread starter macrumors 6502a

    Dec 12, 2005
    I know i should of uploaded the full code but i have worked out how to do it, heres the code for anyone else that might find this later.

    NSEnumerator *searchEnum = [ssidDic objectEnumerator];
    BOOL ssidFound = NO;
    NSMutableDictionary *nextSsidDict;
    while (nextSsidDict = [searchEnum nextObject]) {
    if ([[nextSsidDict objectForKey:mad:"SSID"] isEqualToString:ssid]) {
    ssidFound = YES;
    source = [nextSsidDict objectForKey:script];

Share This Page