不允许分配给“readonly"返回结果,但属性声明为“readwrite" [英] Assigning to 'readonly' return result not allowed, but property is declared "readwrite"

查看:17
本文介绍了不允许分配给“readonly"返回结果,但属性声明为“readwrite"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有 readwrite int 属性的类:

@interface PlayScene : UIView@property (readwrite,assign) int Figure1;@property (readwrite,assign) int Figure2;@property (readwrite,assign) int Figure3;

但是当我尝试更改属性的值时,出现错误:

[self Figure1] = 1;

<块引用>

不允许将 Objective-C 消息的返回结果分配给只读"

有什么问题?

解决方案

语法错误!

打电话

[self setFigure1:1];

self.Figure1 = 1;

(这是一样的,感谢@synthesize [我希望你添加了一个合成器]!)

并且:顺便说一句:您可以为实例变量使用小写-驼峰式.这是一种全球通用的.:)

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. :)

这篇关于不允许分配给“readonly"返回结果,但属性声明为“readwrite"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆