Did the way how to globally import files change in Xcode 6 / iOS 8?

后端 未结 3 1638
既然无缘
既然无缘 2020-12-17 23:23

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

相关标签:
3条回答
  • 2020-12-17 23:33

    In Xcode 6 the project's .pch file not anymore generated automatically but if you want one then you can create a .pch file yourself. Do this as below;

    Goto->File->New->File->(Under iOS)Other->PCH File->Next
    

    After entering the name for the file and saving it, go to "Build Settings" and set the insert the value for "prefix header" as "YourProjectName/YourPCHFileName.pch". And if the "Precompile Prefix header" is set to "No" then change it to "Yes". Now you can put any file you want to import globally, but keeping everything here is not a good practice.

    0 讨论(0)
  • 2020-12-17 23:40

    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. Add new PCH file to the project - New file > Other > PCH file

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

    0 讨论(0)
  • 2020-12-17 23:47

    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.

    0 讨论(0)
提交回复
热议问题