开发者

What happens when I don't include a header file

In xcode, when I add a new objective-c f开发者_如何转开发ile, there's a checkbox where it says something like "Add header file". In what condition should I untick that box and what would it do if I did?


You can skip the header file for any object file that does not need to separately declare any of its symbols.

This is fairly common in CLI-based applications. The “C runtime” (e.g. crt1.o) knows how to call main, so you can usually omit a header file for the .c file that defines your main function (assuming your application has only a single source file or none of the other source files reference symbols that are defined in the same file as main).

The main.m file from the UDPEcho sample is an example of an Objective C file that does not need a .h file.

Most of the “modules” in Cocoa-based applications require a header file because they will need to export at least one symbol to some other bit of your application. Sometimes you need to send a message to an instance of a class defined in another file, sometimes Interface Builder (or whatever) needs to know which actions and outlets are available in your classes, et cetera. The easiest way to make this information available is via a header file.


Check the checkbox if you will need a different .m or .c file to be able to access symbols defined in the .m file you're creating. Those symbols will need the be declared in the .h file created for you when you check the checkbox. For example, a class declaration used in other files would belong in your header file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜