2011-01-15 2 views
0

왜 "반환 값은 캐스트가없는 정수에서 포인터를 만듭니다"라는 경고가 있습니까?경고 "반환은 캐스트가없는 정수에서 포인터를 만듭니다"

NSString과 int가 들어있는 "Person"개체가 있습니다.

 
-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row 
{ 
Person *thePerson = [theList objectAtIndex:row]; 
if (tableColumn == nameTableColumn) 
    { 
     return thePerson.theName; 
    } 
    else if (tableColumn == ageTableColumn) 
    { 
     return thePerson.theAge; 
    } 
    else 
     return nil; 
} 

어떤 이유로 인해 Age 인스턴스 변수에 포인터에 대한 경고가 표시됩니다. 이상 하네. 왜 그런지 알고 싶다.

답변

1

id는 일반 객체의 형태이며, (실제로는 포인터 당신은 그것을 선언하지 않더라도 '*'). int은 개체가 아니므로 경고가 표시됩니다. 이 방법을 사용하려는 경우 NSNumber :

0

int은 값 유형이지만 id은 임의의 Objective-C 포인터 유형에 해당합니다.

당신은 NSNumberint을 포장하고 반환 할 수 있습니다

return [NSNumber numberWithInt:thePerson.theAge]; 
관련 문제