#使用尖括号导入< >和引号“ ”

发布于 2024-12-18 03:55:16 字数 412 浏览 0 评论 0 原文

我想知道当您在 Objective-C 中导入文件时,是什么决定了您是否允许使用 还是 "Header.h" 。到目前为止,我的观察是,您对项目中已获得实现源的文件使用引号 "" ,并使用尖括号 <>当您引用库或框架时。

但这到底是如何运作的呢?我需要做什么才能让我自己的类使用括号?现在 Xcode 不允许我为自己的标头执行此操作。

另外,通过查看一些框架标头,我发现标头通过 相互引用。 是如何工作的?它看起来很像Java中的包,但据我所知,Objective-C中没有包这样的东西。

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.

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.

Also, by looking in some frameworks headers, I see that the headers reference each other with <frameworkname/file.h>. How does that work? 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

深府石板幽径 2024-12-25 03:55:16

Objective-C 在这一点上与 C/C++ 有共同之处;带引号的形式用于“本地”包含文件(您需要指定当前文件的相对路径,例如 #include "headers/my_header.h"),而尖括号形式是对于“全局”包含——在传递给编译器的包含路径中的某个位置找到的包含(例如#include )。

因此,要拥有自己的标头,请使用 < > 不是 " " 您需要将头目录的相对路径或绝对路径传递给编译器。请参阅“如何为 Xcode 添加全局包含路径” 有关如何在 Xcode 中执行此操作的信息。

有关详细信息,请参阅此 MSDN 页面

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>).

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.

See this MSDN page for more info.

萌辣 2024-12-25 03:55:16

在 C 中,约定是在“系统”目录中搜索 <> 括号中的头文件,在用户或本地目录中搜索 ""

我想系统和本地的定义有点模糊。我相信它会在包含路径或 CPPFLAGS 中的系统目录中查找 ,并在本地目录或使用 -I 指定编译器的目录中搜索“header.h”文件。

我认为 Objective-C 的工作原理类似。

In C, the convention is that header files in <> bracket are searched in 'system' directories and "" in user or local directories.

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 <header.h>, and local directory or directory specified with -I to compiler are searched for "header.h" files.

I assume it works similarly for Objective-C.

尘曦 2024-12-25 03:55:16

要使用尖括号形式导入您自己的类,< >,您必须将头文件(.h 文件)放在编译器的 lib 文件夹中,或者设置一个指向您的 的 SYSTEM VARIABLE >lib 文件夹。

To import your own classes using angled bracket form, < >, you have to put the header files (.h files) in the lib folder of the compiler or set a SYSTEM VARIABLE pointing to your lib folder.

时光磨忆 2024-12-25 03:55:16

#import <> vs ""

- 尖括号告诉预处理器在特殊预先指定的系统中进行搜索目录。例如,您导入系统标头,例如 或添加的框架。

"Name.h" - 引号告诉预处理器在当前目录中搜索。如果未找到标头,预处理器会尝试使用 。通常您应该将其与项目文件一起使用。

#import <> vs ""

<Name.h> - Angle brackets tells the preprocessor to search in a special predesignated system's directories. For example, you import systems headers, like <UIKit/UIKit.h> or added frameworks.

"Name.h" - Quotation marks tells the preprocessor to search in a current directory. If a header was not found, the preprocessor tries to use <Name.h>. Usually you should use it with your project's files.

维持三分热 2024-12-25 03:55:16

或者将始终搜索用户路径设置为YES,以便您可以使用尖括号。

Or set Always Search User Path to YES so you can use angle brackets.

不甘平庸 2024-12-25 03:55:16

Xcode 有两种类型的搜索路径:

  1. 用户标头搜索路径
  2. 标头搜索路径

如果您将自己的包含文件夹添加到标头搜索路径中,则可以毫无问题地使用尖括号。

There are two types of search paths is Xcode:

  1. User header search paths
  2. Header search paths

If you add your own include folders into Header Search Paths, you can use angled brackets without any problem.

四叶草在未来唯美盛开 2024-12-25 03:55:16

使用尖括号,例如,您可以导入系统文件。

您可以使用双引号 "Person.h" 导入本地文件(您创建的文件)并告诉编译器在哪里查找它们。

With angle brackets e.g. <Foundation/Foundation.h> you import system files.

You use double quotes "Person.h" to import local files (files that you created) and to tell the compiler where to look for them.

遮了一弯 2024-12-25 03:55:16

如果这是一个 Xcode 项目并且您想要将其包含在框架中,请打开要包含的头文件。然后,打开 Xcode 最右侧的选项卡,在“目标成员资格”下,单击您希望从中使用文件的框架。

例如,如果您的框架是 AlphaTools,标头是 AceHeader,那么您将在目标成员资格上选择 AlphaTools,以便您可以访问 < AlphaTools/AceHeader.h

If this is an Xcode project and you want to include it in a framework, have the header file you want to included open. Then, open Xcode's rightmost tab and under "Target Membership", click on the framework you want your file to available from.

E.g., if your framework is AlphaTools and your header, AceHeader, then you'll select AlphaTools on Target Membership so you can access < AlphaTools/AceHeader.h.

心意如水 2024-12-25 03:55:16

什么是头文件?
头文件包含函数和变量的定义,可以通过使用预处理器#include 语句将这些函数和变量合并到任何 C 程序中。每个编译器都提供标准头文件,涵盖一系列区域、字符串处理、数学、数据转换、打印和变量读取。
Ex- #include 它包含有关编译器中的输入(如 scanf())和输出(如 printf() 函数等)的信息。

包括

1) #包括:-
它是一个预处理器,在主函数处理之前进行处理。
预处理器的主要工作是初始化程序的环境,即带有头文件的程序。
2).h:-
(头文件) 头文件是扩展名为 .h 的文件,其中包含 C 函数声明和宏定义,并在多个源文件之间共享。
问)头文件有两种类型:程序员编写的文件和编译器附带的文件?
A) 在尖括号中
角括号形式用于“全局”包含——那些在传递给编译器的包含路径上的某个位置找到的内容(例如#include)
它用于使用编译器中已定义的库函数。
在 C 中,约定是 <> 中的头文件在“系统”目录中搜索括号
B) 引号:-“header.h”
带引号的形式用于“本地”包含文件(您需要指定当前文件的相对路径,例如#include“headers/my_header.h”)
在 C 中,惯例是在用户或本地目录中搜索“”中的头文件。
其中一个文件要包含在另一个文件中。(文件包含)。
它可以在两种情况下使用:
情况1:如果我们有一个非常大的程序,代码最好分成几个不同的文件,每个文件包含一组相关的函数。
情况2:我们编写的所有程序中,有一些函数和微定义是我们最需要的。
前任

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文