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

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

问题描述

我想知道是什么决定你是否被允许使用< Header.h> Header.h当你在Objective-C中导入文件时。到目前为止,我的观察结果是您使用引号来获取项目中您已获得实现源的文件,以及尖括号<> 。



但这究竟是怎么回事?为了让我自己的类使用括号,我需要做些什么?现在Xcode不允许我为自己的标题做这个。



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

解决方案

Objective-C与C / C ++有共同之处;引用的表单用于本地包含文件(您需要指定当前文件的相对路径,例如 #includeheaders / my_header.h),而angle-bracket形式用于global包括 - 那些在传递给编译器的include路径上找到的那些(例如 #include< math.h> )。 / p>

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



请参阅此MSDN页面了解更多信息。


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.

解决方案

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.

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

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