【问题标题】:Assigning to 'readonly' return result not allowed, but property is declared "readwrite"不允许分配给“只读”返回结果,但属性被声明为“读写”
【发布时间】:2012-05-05 10:04:59
【问题描述】:

我有一个具有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 消息的“只读”返回结果

有什么问题?

【问题讨论】:

  • 请包含您用于“尝试更改其值”的代码。
  • 与方法一样,所有@property 声明都应始终以小写字母开头。
  • 类名的大写首字母:GameOverMenu.

标签: objective-c properties compiler-errors


【解决方案1】:

语法错误!

打电话

[self setFigure1:1];

self.Figure1 = 1;

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

并且:顺便说一句:您可以使用小写驼峰式作为您的实例变量。这有点全球通用。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多