接口类型不能静态分配? [英] Interface type cannot be statically allocated?

查看:238
本文介绍了接口类型不能静态分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把它放在我的视图对象的头文件中:

I tried to put this in the header file of my view object:

@property (nonatomic) UIColor color;

以存储应在此视图中绘制的线条的颜色。

to store the color that lines should be drawn with in this view.

Xcode在此行上给我一个错误:

Xcode gives me an error on this line:


接口类型不能静态分配

Interface type cannot be statically allocated

这是什么意思,我该怎么办?

What does that mean, and what should I do?

编辑:

我添加了一个*,在合成的时候,它说:

I did add a *, and at the point of synthesis, it said:

ARC禁止合成Objective C的属性对象与未指定的所有权或存储属性?

ARC forbid synthesizing a property of Objective C object with unspecified ownership or storage attribute?

推荐答案

您的变量是一个对象类型,因此必须声明为指针:

Your variable is for an object type, and as such must be declared as a pointer:

@property (nonatomic) UIColor * color;    // Note the asterisk

静态分配在这种情况下意味着该对象的内存是在编译时分配。然而,Obj-C中的所有对象都在运行时分配并通过指针访问。

"Statically allocated" in this case would mean that the memory for that object was allocated at compile-time. All objects in Obj-C, however, are allocated at runtime and accessed through pointers.

接口类型是一种过于技术性的术语,对编译器有意义,在这里不是非常重要。这意味着 UIColor 表示编译器期望您与变量 color 接口 c>。指向的对象的实际类型可能不同(与类别相同)集群,例如 NSString )。

"Interface type" is kind of an overly-technical term that's meaningful to the compiler, and not terribly important here. It means that UIColor represents the interface through which the compiler expects you to interact with the variable color. The actual type of the object pointed to may be different (as with a class cluster like NSString).

这篇关于接口类型不能静态分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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