I have a NSMUtableArray and a NSMutableDictionary. My code gets objects from an NSArray into a NSMUtableDictionary. Then add those NSMUtableDictionary objects into an NSMutableArray
this is my code
`
NSArray *sqlAllarray=[[NSArray alloc]initWithArray:[sqlite executeQuery:@"SELECT * FROM dir_bill"]];
for (NSMutableDictionary *alldataDict in sqlAllarray ) {
paydate2=[fmtDate2 dateFromString:[alldataDict valueForKey:@"bill_dateDue"]];
if ([paydate1 compare:paydate2]==NSOrderedDescending || [paydate2 compare:paydate1]==NSOrderedSame) {
appDel.untillPaydayArray=[[NSMutableArray alloc]init];//addObject:[alldataDict copy]];
[appDel.untillPaydayArray addObject:[alldataDict copy]];
}
}`
But it takes only the last NSMUtableDictionary data into the NSMUtableArray. How can I solve this problem.
Thanks
You are creating a new mutable array during every iteration of the loop. There are a few other issues in this code. Try this:
1) No need for the extra NSArray creation.
2) You need to initialize the array once, before the loop. You had this in the loop so each iteration resulted in the array being reset.
5) No need to check for descending and equal. Just check for ascending.