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

AbhishekApple

macrumors member
Original poster
Aug 5, 2010
86
0
The arry has value as==>
arry = 1~Below - $0.99,2~$1.00 - $1.99,3~$2.00 - $2.99,4~$3.00 - Above;

i want NSDictionary to be filled with above values in sequential order (ASC/DSC) with key value pair...
but the ordering is not proper!!!!!!!!!!!


Also Checkout the index value of NSDicitonary why are they not incrementing by 1 like 0,1,2,3,4....

Code:
- (void)requestFinished:(ASIHTTPRequest *)request
{
	
NSString *responseString = [request responseString];
NSArray *arry;
arry= [responseString componentsSeparatedByString:@","];
for (int i=[arry count]-1; i>=0; i--) {
NSArray *arryValue = [[arry objectAtIndex:i] componentsSeparatedByString:@"~"];
[dictPrice setObject:[arryValue objectAtIndex:1] forKey:[arryValue objectAtIndex:0]];
}
}

the Log file shows following
count=4

when i=3;
Code:
Printing description of dictPrice:
<CFDictionary 0xc038cfc0 [0x1e3bca0]>{type = mutable, count = 2, capacity = 3, pairs = (
	[COLOR="Red"]0 [/COLOR]: <CFString 0xcc820ff0 [0x1e3bca0]>{contents = "4"} = 
<CFString 0xcc822fe0 [0x1e3bca0]>{contents =[COLOR="Red"] "$3.00 - Above"[/COLOR]}
	[COLOR="red"]3[/COLOR] : <CFString 0xcc86eff0 [0x1e3bca0]>{contents = "3"} =
 <CFString 0xcc870fe0 [0x1e3bca0]>{contents =[COLOR="red"] "$2.00 - $2.99"[/COLOR]}
)}

when i=2;
Code:
Printing description of dictPrice:
<CFDictionary 0xc038cfc0 [0x1e3bca0]>{type = mutable, count = 3, capacity = 3, pairs = (
	[COLOR="red"]0[/COLOR] : <CFString 0xcc820ff0 [0x1e3bca0]>{contents = "4"} =
 <CFString 0xcc822fe0 [0x1e3bca0]>{contents =[COLOR="red"] "$3.00 - Above"[/COLOR]}
	[COLOR="red"]1[/COLOR] : <CFString 0xcc8ceff0 [0x1e3bca0]>{contents = "2"} = 
<CFString 0xcc8d0fe0 [0x1e3bca0]>{contents =[COLOR="red"] "$1.00 - $1.99[/COLOR]"}
[COLOR="red"]	3 [/COLOR]: <CFString 0xcc86eff0 [0x1e3bca0]>{contents = "3"} =
 <CFString 0xcc870fe0 [0x1e3bca0]>{contents = [COLOR="red"]"$2.00 - $2.99[/COLOR]"}
)}

when i=1;
Code:
Printing description of dictPrice:
<CFDictionary 0xc038cfc0 [0x1e3bca0]>{type = mutable, count = 4, capacity = 6, pairs = (
	[B][COLOR="Red"]0 [/COLOR][/B]: <CFString 0xcc820ff0 [0x1e3bca0]>{contents = "4"} = 
<CFString 0xcc822fe0 [0x1e3bca0]>{contents =[COLOR="Red"] "$3.00 - Above"[/COLOR]}
	[B][COLOR="red"]1[/COLOR][/B] : <CFString 0xcc8ceff0 [0x1e3bca0]>{contents = "2"} = 
<CFString 0xcc8d0fe0 [0x1e3bca0]>{contents =[COLOR="red"] "$1.00 - $1.99"[/COLOR]}
	[B][COLOR="red"]4 [/COLOR][/B]: <CFString 0xcc924ff0 [0x1e3bca0]>{contents = "1"} = 
<CFString 0xcc926fe0 [0x1e3bca0]>{contents = [COLOR="red"]"Below - $0.99"[/COLOR]}
	[B][COLOR="red"]7 [/COLOR][/B]: <CFString 0xcc86eff0 [0x1e3bca0]>{contents = "3"} = 
<CFString 0xcc870fe0 [0x1e3bca0]>{contents =[COLOR="red"] "$2.00 - $2.99[/COLOR]"}
)}
 

adrian.oconnor

macrumors 6502
Jan 16, 2008
326
3
Nottingham, England
You need to use an NSArray (or NSMutableArray) to get things stored in order. If you want key/value pairs you need to encapsulate the data within a class. Once you've done that you can even use NSMutableArray sortUsingSelector to order the results if you need to.
 

AbhishekApple

macrumors member
Original poster
Aug 5, 2010
86
0
If you want key/value pairs you need to encapsulate the data within a class. Once you've done that you can even use NSMutableArray sortUsingSelector to order the results if you need to.

can u give example on this....

how to create instance of class dynamically, and later use it?

like here if i want 10 instance i can define it statically but how to define dynamically so that later i can get the instance name to fetch its variables

ClassName *obj[10];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.