I'm using this code with ARC:
NSMutableDictionary *datesDict = [[NSMutableDictionary alloc]init];
NSMutableArray *datesArray = [[NSMutableArray alloc]init];
for (NSString *key in programsArray) {
datesArray = [_onDemandDictionary objectForKey:key];
NSMutableArray *newDates = [[NSMutableArray alloc]init];
int count;
for (count = 0; count <datesArray.count; count++) {
NSMutableDictionary *programsDict = [[NSMutableDictionary alloc]init];
programsDict = [datesArray objectAtIndex:count];
[newDates addObject:[programsDict objectForKey:@"date"]];
}
[datesDict setObject:newDates forKey:key];
}
But when I run the analyzer tool I'm getting value stored to (datesArray and programsDict) during its initialization is never read on lines:
NSMutableArray *datesArray = [[NSMutableArray alloc]init];
programsDict = [datesArray objectAtIndex:count];
Why is this happening how do I get hid of the warning?
Thank you!
The issue is you create a new NSMutableArray
and assign it to datesArray
at the beginning
NSMutableArray *datesArray = [[NSMutableArray alloc]init];
Then almost immediately after you assign a completely different value to datesArray
with
datesArray = [_onDemandDictionary objectForKey:key];
I would just start with
NSMutableArray *datesArray = nil;
It's the same concept for programsDict
.
On line 2, you create a new array datesArray
.
Then, on line 6 (first line of the for loop), you set a new value to datesArray
.
The compiler is just warning you that the line 2 has no effect, and that the code is bugged (in the sense it does not do what you expect).
True, the programsArray
could be an empty array, and in this case you want datesArray
to just be initialized to use it after the snippet you showed us, but it would be better to make this explicit.
For programsDict
, it is even easier: you initialize it with ... alloc] init]
then set it to an object of datesArray
, making the first operation useless.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With