在Xcode 6 / iOS 8中如何全局导入文件的方式有变化吗? [英] Did the way how to globally import files change in Xcode 6 / iOS 8?

查看:91
本文介绍了在Xcode 6 / iOS 8中如何全局导入文件的方式有变化吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经在文件 AppName -prefix中进行全局导入(即我的Xcode项目中所有源文件可见的导入)。 pch

I used to do my global imports (i.e. imports that would be visible to all source files in my Xcode project) in the file AppName-prefix.pch.

但是,现在在Xcode 6(和iOS 8)环境中,创建新项目后,此文件不再自动生成。

However, now in an Xcode 6 (and iOS 8) environment, after having created a new project, this file is not automatically generated any more.

我的问题是如何在Xcode 6中正确进行全局导入?我可以创建自己的 AppName -prefix.pch 并最终使用这个吗?

My question is how to properly do global imports in Xcode 6? Can I just create my own AppName-prefix.pch and use this one eventually?

注意:使用 Cocoapods 时,会生成名为 Pods- AppName -Bolts-prefix.pch 的文件。但全球进口不会与这个一起使用。

Note: When using Cocoapods, a file called Pods-AppName-Bolts-prefix.pch is generated. But global imports won't be working with this one.

推荐答案

Apple终于明白,拥有全球依赖是非常非常糟糕的做法。
理想情况下,您需要停止使用PCH文件,因为它会使其他文件变得非常混乱,并且会重复使用代码。

Apple finally understood that having global dependency is a Very Very bad practice. Ideally you need to stop using PCH files, because it makes other files very messy, and breaks code reusing.

无论如何,这是解决方案

Anyway, here is solution


  1. 将新的PCH文件添加到项目中 - 新文件>其他> PCH文件

  1. Add new PCH file to the project - New file > Other > PCH file

目前该项目的构建设置选项 - 前缀头的值设置为您的PCH文件的名称,项目名称为前缀 -
即名为TestProject项目和PCH文件命名为 MyPrefixHeaderFile',将值'TestProject / MyPrefixHeaderFile.pch'添加到plist。

At the project 'Build Settings' option - set the value of 'Prefix Header' to your PCH file name, with the project name as prefix - i.e. for project named 'TestProject' and PCH file named 'MyPrefixHeaderFile', add the value 'TestProject/MyPrefixHeaderFile.pch' to the plist.

这篇关于在Xcode 6 / iOS 8中如何全局导入文件的方式有变化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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