Objective C - 需要左值作为赋值的左操作数
我收到此代码的错误(需要左值作为赋值的左操作数):
[[addAlertViewController alertsArray] = [NSMutableArray arrayWithObjects:nil] retain];
如何修复它?
I get the error (Lvalue required as left operand of assignment) for this code:
[[addAlertViewController alertsArray] = [NSMutableArray arrayWithObjects:nil] retain];
How can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
了解左值和右值有助于破译编译器警告。左值是要被赋值的东西,右值是可以进行赋值的东西。 有关维基百科的更多信息
右值也可以是左值,例如a = b = c(其中 c 是左值 b 的右值,但 b 是左值 a 的右值)。
每当您看到“需要左值”,然后查看 = 运算符的左侧时,就会发现那里有错误。
Knowing what an lvalue and rvalue will help when deciphering compiler warnings. A lvalue is something that will be assigned and a rvalue is something that can do the assigning. More info on wikipedia
An rvalue can also be a lvalue, like in the case of a = b = c (where c is an rvalue to lvalue b, but then b is a rvalue to the lvalue a).
anytime you see "lvalue required" then look on the left of the = operator, there is an error there.
适当的代码如下:
请注意,您已在
addAlertViewController
的类的@interface
中声明:并在您的实现文件
而且..我同意@taskinoor,RTFM。
The appropriate Code is as follows:
Be careful that you have declared in your
@interface
ofaddAlertViewController
's Class:And in your implementation file
And.. I'll agree with @taskinoor, RTFM.