#import 使用尖括号 <>和引号" [英] #import using angle brackets < > and quote marks " "

查看:41
本文介绍了#import 使用尖括号 <>和引号"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道当您在 Objective 中导入文件时,是什么决定了您是否可以使用 <Header.h>"Header.h"-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.

但这究竟是如何工作的呢?我需要做什么才能让我自己的课程使用方括号?现在 Xcode 不允许我为自己的头文件这样做.

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.

此外,通过查看一些框架标题,我发现这些标题通过 <frameworkname/file.h> 相互引用.那个是如何工作的?它看起来很像 Java 中的包,但据我所知,Objective-C 中没有包这样的东西.

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.

推荐答案

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

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

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

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.

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

See this MSDN page for more info.

这篇关于#import 使用尖括号 &lt;&gt;和引号"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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