Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
739 views
in Technique[技术] by (71.8m points)

objective c - Interface type cannot be statically allocated?

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 gives me an error on this line:

Interface type cannot be statically allocated

What does that mean, and what should I do?

EDIT:

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

"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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...