objective-c #import 使用尖括号 < > 和引号 " "
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1044360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
#import using angle brackets < > and quote marks " "
提问by quano
I'm wondering what decides whether you're allowed to use <Header.h>or "Header.h"when you're importing files in Objective-C. So far my observation has been that you use the quote marks ""for files in your project that you've got the implementation source to, and angle brackets <>when you're referencing a library or framework.
我想知道是什么决定了您是否可以使用<Header.h>或"Header.h"何时在 Objective-C 中导入文件。到目前为止,我的观察是,当您引用库或框架时,您对""项目中获得实现源的文件使用引号,并使用尖括号<>。
But how exactly does that work? What would I have to do to get my own classes to use the brackets? Right now Xcode will not allow me to do that for my own headers.
但这究竟是如何工作的呢?我需要做什么才能让我自己的类使用括号?现在 Xcode 不允许我为自己的头文件这样做。
Also, by looking in some frameworks headers, I see that the headers reference each other with <frameworkname/file.h>. How does thatwork? It looks a lot like packages in Java, but as far as I know, there is no such thing as a package in Objective-C.
此外,通过查看一些框架头文件,我看到这些头文件相互引用<frameworkname/file.h>. 如何做那工作的?它看起来很像 Java 中的包,但据我所知,Objective-C 中没有包这样的东西。
回答by Mark Pim
Objective-C has this in common with C/C++; the quoted form is for "local" includes of files (you need to specify the relative path from the current file, e.g. #include "headers/my_header.h"), while the angle-bracket form is for "global" includes -- those found somewhere on the include path passed to the compiler (e.g. #include <math.h>).
Objective-C 与 C/C++ 有这个共同点;引用的形式用于“本地”包含文件(您需要指定当前文件的相对路径,例如#include "headers/my_header.h"),而尖括号形式用于“全局”包含 - 那些在包含路径中找到的传递给编译器(例如#include <math.h>)。
So to have your own headers use < >not " "you need to pass either the relative or the absolute path for your header directory to the compiler. See "How to add a global include path for Xcode"for info on how to do that in Xcode.
所以,有自己的头用< >不" ",你需要或者相对或者你的头目录到编译器的绝对路径通过。有关如何在 Xcode 中执行此操作的信息,请参阅“如何为 Xcode 添加全局包含路径”。
See this MSDN pagefor more info.
有关更多信息,请参阅此 MSDN 页面。
回答by stefanB
In C the convention is that header files in <> bracket are searched in 'system' directories and "" in user or local directories.
在 C 中,约定是在“系统”目录中搜索 <> 括号中的头文件,在用户或本地目录中搜索“”。
The definition of system and local is a bit vague I guess. I believe it looks in system directories in include path or in CPPFLAGS for and local directory or directory specified with -I to compiler are searched for "header.h" files.
我猜系统和本地的定义有点模糊。我相信它会在包含路径或 CPPFLAGS 中的系统目录中查找,并在本地目录或使用 -I 指定的目录中查找编译器的“header.h”文件。
I assume it works similarly for Objective-C.
我认为它对 Objective-C 的工作方式类似。
回答by Rodrigo Reis
To import your own classes using "< >" you have to put the header files (*.h) in the lib folder of compiler or set a SYSTEM VARIABLES ponting to your lib folder.
要使用“< >”导入您自己的类,您必须将头文件 (*.h) 放在编译器的 lib 文件夹中,或者将系统变量设置为您的 lib 文件夹。
回答by Ida88
Or set Always Search User Pathto YESso you can use angle brackets.
或者设置Always Search User Path为,YES以便您可以使用尖括号。
回答by soupwaylee
With angle brackets e.g. <Foundation/Foundation.h>you import system files.
使用尖括号,例如<Foundation/Foundation.h>您导入系统文件。
You use double quotes "Person.h"to import local files (files that you created) and to tell the compiler where to look for them.
您使用双引号"Person.h"导入本地文件(您创建的文件)并告诉编译器在哪里查找它们。
回答by yoAlex5
<Name.h>- Angle bracketstells to preprocessor to search in a specialpre-designated system's directories. For example you import systems headers like <UIKit/UIKit.h>or added frameworks
<Name.h>-Angle brackets告诉预处理器在一个特殊的预先指定的系统目录中搜索。例如,您导入系统标头<UIKit/UIKit.h>或添加的框架
"Name.h"- Quotation markstells to preprocessor to search in a currentdirectory. If a header was not found the preprocessor try to use <Name.h>. Usually you should use it with your project's files
"Name.h"-Quotation marks告诉预处理器在当前目录中搜索。如果未找到标头,预处理器会尝试使用<Name.h>. 通常你应该将它与你的项目文件一起使用
回答by fatihk
Just stumbled upon the same problem, there are 2 types of search paths is Xcode:
刚刚偶然发现了同样的问题,Xcode 有两种类型的搜索路径:
User Header Search Paths
Header Search Paths
If you add your own include folders into Header Search Paths, you can use angled brackets without any problem.
如果您将自己的包含文件夹添加到标题搜索路径中,则可以毫无问题地使用尖括号。
回答by anitesh975
WHAT IS HEADER FILE ? Header files contain definitions of functions and variables which can be incorporated into any C program by using the?pre-processor?#include statement.?Standard header files?are provided with each compiler, and cover a range of areas, string handling, mathematical, data conversion, printing and reading of variables. Ex- #include it contain the information about input like scanf(),and out put like printf() function and etc in a compiler.
什么是头文件?头文件包含函数和变量的定义,这些函数和变量可以通过使用?预处理器?#include 语句合并到任何 C 程序中。?标准头文件?随每个编译器提供,涵盖了一系列领域、字符串处理、数学,数据转换,打印和读取变量。Ex- #include 它包含有关输入的信息,如 scanf(),输出如 printf() 函数等。
INCLUDE
包括
1) #INCLUDE:- It is a pre-processor that process before process of main function. The main work of pre-processor is to initialize the environment of program i.e that is the program with the header file. 2).h:- (Header file) A header file is a file with extension?.h?which contains C function declarations and macro definitions and to be shared between several source files. Q) There are two types of header files: the files that the programmer writes and the files that come with your compiler ? A)In a angular brackets Angular-bracket form is for "global" includes -- those found somewhere on the include path passed to the compiler (e.g.?#include) It is used for using of library function which is all ready define in compiler. In C the convention is that header files in <> bracket are searched in 'system' directories? B) Quote marks:- “header.h” quoted form is for "local" includes of files (you need to specify the relative path from the current file, e.g.?#include "headers/my_header.h") In C the convention is that header files in?" " are searched in user or local directories. In it one file to be included in another .(FILE INCLUSION). It can be used in two cases: Case 1: If we have a very large program, the code is best divided int several different files,each containing a set of related functions. Case 2: There are some functions and micros definitions that we need at most in all programs that we write. Ex
1) #INCLUDE:- 它是一个预处理器,在主函数的处理之前进行处理。预处理器的主要工作是初始化程序的环境,即带有头文件的程序。2).h:- (Header file) 头文件是一个扩展名为?.h? 的文件,它包含C 函数声明和宏定义并在多个源文件之间共享。问)头文件有两种类型:程序员编写的文件和编译器附带的文件?A)在尖括号中 Angular-bracket 形式用于“全局”包含 - 在传递给编译器的包含路径上找到的那些(例如?#include)它用于使用已在编译器中定义好的库函数. 在 C 中,约定是 <> 括号中的头文件在“系统”中搜索 目录?B) 引号:- “header.h” 引用形式用于“本地”包含文件(您需要指定当前文件的相对路径,例如?#include "headers/my_header.h")在 C 中的约定在用户或本地目录中搜索头文件吗?" "。其中一个文件要包含在另一个文件中。(文件包含)。它可以用于两种情况: 情况1:如果我们有一个非常大的程序,最好将代码分成几个不同的文件,每个文件包含一组相关的函数。案例2:在我们编写的所有程序中,我们最多需要一些函数和微定义。前任 ) 在 C 中,约定是在用户或本地目录中搜索 ?" " 中的头文件。其中一个文件要包含在另一个文件中。(文件包含)。它可以用于两种情况: 情况1:如果我们有一个非常大的程序,最好将代码分成几个不同的文件,每个文件包含一组相关的函数。案例2:在我们编写的所有程序中,我们最多需要一些函数和微定义。前任 ) 在 C 中,约定是在用户或本地目录中搜索 ?" " 中的头文件。其中一个文件要包含在另一个文件中。(文件包含)。它可以用于两种情况: 情况1:如果我们有一个非常大的程序,最好将代码分成几个不同的文件,每个文件包含一组相关的函数。案例2:在我们编写的所有程序中,我们最多需要一些函数和微定义。前任

