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.
However, now in an Xcode 6 (and iOS 8) environment, after having created a new project, this file is not automatically generated any more.
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?
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 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
Add new PCH file to the project - New file > Other > PCH file
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.
You can creTe your own, but the point really is that you shouldn't have global dependencies, you should explicitly import only what is required into each class. Indeed, in your .h files you should endeavour to use @class
for everything and only import into your .m file. This approach makes the dependencies of a class very clear and reduces the likelihood of dependency circularities, which are both very good things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With