在 xcode 的 .pch 文件中导入的类不起作用,为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20141468/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:20:19  来源:igfitidea点击:

Classes imported in .pch file in xcode not working, why?

iosobjective-cxcode

提问by Hashim Khan

I have a concern with my .pch file in Xcode 5.

我对 Xcode 5 中的 .pch 文件感到担忧。

I have following code in my .pch file--

我的 .pch 文件中有以下代码——

#ifdef __OBJC__

#import <Example/Example.h>

#endif

But when i use Example.h class in my code it is not working. When i use code like-

但是当我在我的代码中使用 Example.h 类时它不起作用。当我使用代码时 -

[Example sharedInstance];

xcode shows error "Use od undeclared identifier Example". What is the problem?

xcode 显示错误“使用 od 未声明的标识符示例”。问题是什么?

采纳答案by Jasarien

You will need to include the path to the headers in the "Header Search Path" build settings so that the preprocessor/compiler can find the headers.

您需要在“头文件搜索路径”构建设置中包含头文件的路径,以便预处理器/编译器可以找到头文件。

回答by OverToasty

This Screen Shotfrom XCode 6.1shows how I got this to work - and therefore may prove helpful.

这个来自XCode 6.1 的屏幕截图展示了我是如何让它工作的 - 因此可能会有所帮助。

Look at the bold text, mid-way down, in the "Apple LLVM 6.0 - Language"TARGETS / Build Settings area.

查看“Apple LLVM 6.0 - 语言”目标/构建设置区域中粗体文本。

Notice how the bold text "Precompile Prefix Header"has been set to YES, and the path to the pch file in "Prefix Header"is set with ProjectName/YourPCHFile-Prefix.pch

请注意如何将粗体文本"Precompile Prefix Header"设置为YES,并且"Prefix Header" 中pch 文件的路径设置为ProjectName/YourPCHFile-Prefix.pch

Screen Shot from XCode 6.1 showing how to include .pch file

XCode 6.1 的屏幕截图显示了如何包含 .pch 文件