If array is thread safe, what the issue with this function?
Posted
by
Ajay Sharma
on Stack Overflow
See other posts from Stack Overflow
or by Ajay Sharma
Published on 2011-09-23T13:07:16Z
Indexed on
2012/06/02
4:40 UTC
Read the original article
Hit count: 276
I am totally lost with the things that is happening with my code.It make me to think & get clear with Array's thread Safe concept. Is NSMutableArray OR NSMutableDictionary Thread Safe ?
While my code is under execution, the values for the MainArray get's changes although, that has been added to Array.
Please try to execute this code, onyour system its very much easy.I am not able to get out of this Trap.
It is the function where it is returning Array. What I am Looking to do is : -(Array) (Main Array) -->(Dictionary) with Key Value (Multiple Dictionary in Main Array) -----> Above dictionary has 9 Arrays in it.
This is the structure I am developing for Array.But even before
#define TILE_ROWS 3
#define TILE_COLUMNS 3
#define TILE_COUNT (TILE_ROWS * TILE_COLUMNS)
-(NSArray *)FillDataInArray:(int)counter
{
NSMutableArray *temprecord = [[NSMutableArray alloc] init];
for(int i = 0; i <counter;i++)
{
if([temprecord count]<=TILE_COUNT)
{
NSMutableDictionary *d1 = [[NSMutableDictionary alloc]init];
[d1 setValue:[NSString stringWithFormat:@"%d/2011",i+1] forKey:@"serial_data"];
[d1 setValue:@"Friday 13 Sep 12:00 AM" forKey:@"date_data"];
[d1 setValue:@"Description Details " forKey:@"details_data"];
[d1 setValue:@"Subject Line" forKey:@"subject_data"];
[temprecord addObject:d1];
d1= nil;
[d1 release];
if([temprecord count]==TILE_COUNT)
{
NSMutableDictionary *holderKey = [[NSMutableDictionary alloc]initWithObjectsAndKeys:temprecord,[NSString stringWithFormat:@"%d",[casesListArray count]+1],nil];
[self.casesListArray addObject:holderKey];
[holderKey release];
holderKey =nil;
[temprecord removeAllObjects];
}
}
else {
[temprecord removeAllObjects];
NSMutableDictionary *d1 = [[NSMutableDictionary alloc]init];
[d1 setValue:[NSString stringWithFormat:@"%d/2011",i+1] forKey:@"serial_data"];
[d1 setValue:@"Friday 13 Sep 12:00 AM" forKey:@"date_data"];
[d1 setValue:@"Description Details " forKey:@"details_data"];
[d1 setValue:@"Subject Line" forKey:@"subject_data"];
[temprecord addObject:d1];
d1= nil;
[d1 release];
}
}
return temprecord;
[temprecord release];
}
What is the problem with this Code ? Every time there are 9 records in Array, it just replaces the whole Array value instead of just for specific key Value.
© Stack Overflow or respective owner