开发者

I can't declare this property in the .h file, can i do it in the .m?

I want to create a property out of a view which already has my class imported into it's own .h file, and therefore I cannot import it's .h file into my .h file because it causes problems. This means i have to put it's import into the .m file.

Putting this into the .m file:

View1 *view1;

works fine. But putting in开发者_Go百科 a @property causes problems. I can't seem to find where best to put it to not cause an error. Is there a workaround to this?


You can put this in your @interface in your header file without importing View1.h. Just use a forward declaration like this:

@class View1;

@interface MyClass : NSObject {

}

@property (attrs) View1 *view1;
@end

You can also declare properties in your implementation (.m) file, if you ever need to, with a class extension like so:

@interface MyClass() 

@property (attrs) View1 *somePrivateProperty;
@end

This is useful for other reasons, but not necessary in your case from what you've said. Think of it as a secondary @interface with properties and methods that you might want to hide from other classes which import "MyClass.h"

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜