我无法在 .h 文件中声明此属性,我可以在 .m 中声明此属性吗?
我想从视图中创建一个属性,该视图已将我的类导入到它自己的 .h 文件中,因此我无法将它的 .h 文件导入到我的 .h 文件中,因为它会导致问题。这意味着我必须将其导入到 .m 文件中。
将其放入 .m 文件中:
View1 *view1;
工作正常。但是放入 @property 会导致问题。我似乎找不到最好的放置位置以免导致错误。有解决方法吗?
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将其放入头文件中的 @interface 中,而无需导入 View1.h。只需使用如下所示的前向声明:
如果需要,您还可以在实现 (.m) 文件中声明属性,并使用如下所示的类扩展:
这出于其他原因很有用,但在您的情况下没有必要你说过。将其视为具有属性和方法的辅助 @interface,您可能希望对导入“MyClass.h”的其他类隐藏这些属性和方法
希望有所帮助。
You can put this in your @interface in your header file without importing View1.h. Just use a forward declaration like this:
You can also declare properties in your implementation (.m) file, if you ever need to, with a class extension like so:
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.