分配给“只读”不允许返回结果,但是属性被声明为“readwrite” [英] Assigning to 'readonly' return result not allowed, but property is declared "readwrite"
本文介绍了分配给“只读”不允许返回结果,但是属性被声明为“readwrite”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类 readwrite
int
属性:
@interface PlayScene:UIView
@property(readwrite,assign)int图1;
@property(readwrite,assign)int图2;
@property(readwrite,assign)int图3;
但是当我尝试更改属性的值时,会出现错误:
[self Figure1] = 1;
分配给readonly返回Objective-C消息的结果允许
问题是什么?
解决方案
错误的语法!
调用
[self setFigure1 :1];
或
self.Figure1 = 1;
(同样,感谢@synthesize [我希望你添加了一个综合! / p>
和:BTW:你可能使用小写camelcase作为你的实例变量。这是一种全球共同的。 :)
I have a class with readwrite
int
properties:
@interface PlayScene : UIView
@property (readwrite, assign) int Figure1;
@property (readwrite, assign) int Figure2;
@property (readwrite, assign) int Figure3;
But when I try to change the value of the properties, an error occurs:
[self Figure1] = 1;
assigning to 'readonly' return result of an Objective-C message not allowed
What is the problem?
解决方案
wrong syntax!
call
[self setFigure1:1];
or
self.Figure1 = 1;
(it's the same, thanks to @synthesize [i hope you did add a synthesize]!)
And: BTW: you might use lowercase-camelcase for your instance variable. It's kind of global-common. :)
这篇关于分配给“只读”不允许返回结果,但是属性被声明为“readwrite”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文