在if块中重新分配变量时出现objective-c错误
我遇到一个错误,“从兼容类型'id'分配到'BNRItem',尝试将不同的对象分配给在if块外部声明的变量。为什么我在声明变量并为其赋值时没有得到相同的错误,但在if语句中尝试重新赋值时却得到了错误?谢谢你的帮助在if块中重新分配变量时出现objective-c错误,objective-c,Objective C,我遇到一个错误,“从兼容类型'id'分配到'BNRItem',尝试将不同的对象分配给在if块外部声明的变量。为什么我在声明变量并为其赋值时没有得到相同的错误,但在if语句中尝试重新赋值时却得到了错误?谢谢你的帮助 BNRItem *p = [[[BNRItemStore sharedStore] getHighValueItems] <== no error objectAtIndex:[indexPath row]]; if(indexPath
BNRItem *p = [[[BNRItemStore sharedStore] getHighValueItems] <== no error
objectAtIndex:[indexPath row]];
if(indexPath.section==1){
*p = [[[BNRItemStore sharedStore] getLowValueItems] <== error
objectAtIndex:[indexPath row]];
}
bRitem*p=[[[bRitemStore sharedStore]getHighValueItems]删除*like so
if(indexPath.section==1){
p = [[[BNRItemStore sharedStore] getLowValueItems] objectAtIndex:[indexPath row]];
}
您已经在if上方创建了指针,现在只需赋值。只有在首次声明变量时才应使用解引用运算符(*)
BNRItem *p = nil;
if(indexPath.section==1){
p = [[[BNRItemStore sharedStore] getLowValueItems]
objectAtIndex:[indexPath row]];
}
但在声明中,它不是一个解引用操作符。