Objective-C:在 .h 或 .m 中导入标头? [英] Objective-C: Importing headers in .h or .m?

查看:53
本文介绍了Objective-C:在 .h 或 .m 中导入标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Objective-c 的新手,想知道导入我在课堂上使用的一些外部标头的最佳做法.

I'm new to objective-c and would like to know the best practice for importing some external headers that I use in my class.

我应该将#import "classB.h" 存储在我自己的类 .h 文件中还是在 .m 文件中?

Should I be storing the #import "classB.h" in my own classes .h file or in the .m file?

有什么区别?

谢谢!

推荐答案

在头部和 #import 中放置前向类声明 (@class classB;) 是正确的做法.m

It is proper practice to put a forward class declaration (@class classB;) in the header and #import "classB.h in the .m

前向类声明,如 @class classB; 让编译器知道它应该在以后期望该类,并且此时它不应该抱怨它.

A forward class declaration, like @class classB; lets the compiler know it should expect the class later on, and it shouldn't complain about it at the moment.

这篇关于Objective-C:在 .h 或 .m 中导入标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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