为什么发生警告?

Ruk*_*ora 2 warnings objective-c nsstring ios

我写了代码.

但它的代码发出警告.

它的警告文字是

不兼容的整数到指针转换从'NSInteger'(又名'int')分配给'NSInteger*'(又名'int*')

这是导致警告的代码.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    ...

    apd.newyear = [newys integerValue];//Its error happen on this row.

    apd.newmonth = [newms integerValue];//Its error happen on this row.

    [self dismissViewControllerAnimated:YES completion:nil];

}
Run Code Online (Sandbox Code Playgroud)

Gab*_*lla 13

错误很清楚.

newyear并且newmonth都有类型NSInteger *,你正在尝试NSInteger为它们分配一个.

NSInteger它不是一个对象,它是原生C值,所以你可能在定义apd对象的两个属性时犯了一个错误.

我打赌你有类似的东西

@property NSInteger * newyear;
Run Code Online (Sandbox Code Playgroud)

应该是

@property NSInteger newyear;
Run Code Online (Sandbox Code Playgroud)