2 abcdefgh xyz abcdeFGh_xyz 于 2012.11.15 11:08 提问

objective-c中ARC的问题:初始化的时候无法读取值

先看一下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];
}

在运行解析工具的时候,出现这一句:**stored to (datesArray and programsDict) during its initialization is never read**
在这一句

NSMutableArray *datesArray = [[NSMutableArray alloc]init];
programsDict = [datesArray objectAtIndex:count];

为什么?找不到原因和解决方法,请高人指点,谢谢!

1个回答

prettYYoyic
prettYYoyic   2012.11.15 11:36
已采纳

问题出在你创建新的NSMutableArray.然后在这一句

NSMutableArray *datesArray = [[NSMutableArray alloc]init];

把它分配给datesArray

但是接下来又把一个完全不同的值又分配给了datesArray

datesArray = [_onDemandDictionary objectForKey:key];

所以你最开始只要用这句就可以:

NSMutableArray *datesArray = nil;

和programsDict是一样的

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!