abcdeFGh_xyz
2012-11-15 03:08
采纳率: 69.2%
浏览 2.5k
已采纳

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 2012-11-15 03:36
    已采纳

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

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

    把它分配给datesArray

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

    datesArray = [_onDemandDictionary objectForKey:key];
    

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

    NSMutableArray *datesArray = nil;
    

    和programsDict是一样的

    点赞 打赏 评论

相关推荐 更多相似问题