'NSMutableArray may not respond to ObjectForKey'에 해당되는 글 1건

  1. 2011.07.18 [iphone] NSMutableArray may not respond to ObjectForKey란 에러메세지
iPhone App2011. 7. 18. 14:58

코딩을 하다보니 이런 경고가 계속 떠서 짜증났다.

이런 경고를 없애기 위해서 인터넷 찾아보니

for문 in을 쓸때(c#에서는 foreach) NSmutableArray 컬렉션으로

   for(NSMutableArray *item in afd.foodData)

{

NSNumber *calrorie = [NSNumber numberWithInt:[[item objectForKey:@"calrorie"] intValue]];

count = [NSNumber numberWithInt:[count intValue]+[calrorie intValue]];

NSString *name = [NSString stringWithString:[item objectForKey:@"name"]];

[totalName appendFormat:@"%@ (%d) Cal \n",name,[calrorie intValue]];

}


이런식으로 하니 경고가 발생했다 그래서

   for(NSMutableDictionary *item in afd.foodData)

{

NSNumber *calrorie = [NSNumber numberWithInt:[[item objectForKey:@"calrorie"] intValue]];

count = [NSNumber numberWithInt:[count intValue]+[calrorie intValue]];

NSString *name = [NSString stringWithString:[item objectForKey:@"name"]];

[totalName appendFormat:@"%@ (%d) Cal \n",name,[calrorie intValue]];

}


이렇게 수정하니 경고가 사라졌다.
참고 : http://stackoverflow.com/questions/6196688/how-to-resolve-nsmutablearray-may-not-respond-to-objectforkey
Posted by 동동(이재동)