Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

semaja2

macrumors 6502a
Original poster
Dec 12, 2005
576
18
Adelaide
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
Code:
				/*works*/
				script = [[ssidDic objectAtIndex:0] objectForKey:@"connectSource"];
				/*only partly works result = ("display dialog hello", "--disconnect ScriptCode") */
				script = [ssidDic valueForKey:@"disconnectSource"];

i hope this makes senses
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
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]).
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Just a general tip, if you're comparing strings for equality of content, don't use if aString == anotherString, use if ([aString isEqualToString:anotherString]).
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.
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
Code:
				/*works*/
				script = [[ssidDic objectAtIndex:0] objectForKey:@"connectSource"];
				/*only partly works result = ("display dialog hello", "--disconnect ScriptCode") */
				script = [ssidDic valueForKey:@"disconnectSource"];

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.
 

semaja2

macrumors 6502a
Original poster
Dec 12, 2005
576
18
Adelaide
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];
break;
}
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.