模塊化工做中,會指定庫與庫之間的依賴關係,根據依賴關係分層,但隨着開發進行,依賴關係又慢慢被破壞。如何讓後續的開發者可以不破壞關係?目前有兩種經常使用手段:xcode
這兩種實施起來都挺不方便,咱們的目的是想讓沒有依賴關係的引用直接import不到頭文件,從而提示開發者這個引用非法。ruby
import有兩種形式,<>和"",他們的區別:app
stackoverflow上回答較高的解釋 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。
意思就是雙引號是用於本地的頭文件,須要指定相對路徑,尖括號是全局的引用,其路徑由編譯器提供,如引用系統的庫。但在實際工程裏,不只不用指定相對路徑,並且用<>也是能引用到的。事出有因,繼續看。ide
xcode有個use header map
的開關,這個開關的介紹:Enable the use of Header Maps, which provide the compiler with a mapping from textual header names to their locations, bypassing the normal compiler header search path mechanisms. This allows source code to include headers from various locations in the file system without needing to update the header search path build settings。
意思是開啓這個開關後,在本地會根據當前目錄生成一份文件名和相對路徑的映射,依靠這個映射,咱們能夠直接import工程裏的文件,不須要依靠header search path。第一點中的問題獲得解決,那就直接關閉這個開關吧。模塊化
若是關閉use header map
那麼就涉及到xcode build settings
中的header search path 和 user header search path
了。Header Search Paths:This is a list of paths to folders to be searched by the compiler for included or imported header files when compiling C, Objective-C, C++, or Objective-C++. Paths are delimited by whitespace, so any paths with spaces in them need to be properly quoted.
ui
User Header Search Paths (USER_HEADER_SEARCH_PATHS)
This is a list of paths to folders to be searched by the compiler for included or imported user header files (those headers listed in quotes) when compiling C, Objective-C, C++, or Objective-C++. Paths are delimited by whitespace, so any paths with spaces in them need to be properly quoted. See Always Search User Paths (ALWAYS_SEARCH_USER_PATHS) for more details on how this setting is used. If the compiler doesn't support the concept of user headers, then the search paths are prepended to the any existing header search paths defined in Header Search Paths (HEADER_SEARCH_PATHS).this
二者都是提供search path的,區別在於一個指明是用戶的。而且提到若是編譯器不支持user headers概念,會從header search paths中去尋找。spa
在這裏咱們能夠看到,若是打開了Always Search User Paths
,<>
和""
均可以引用到,若是關閉了,user headers
只能經過""
引用。code
經過這一系列,咱們的方案出來了,關閉use header map
,關閉Always Search User Paths
,經過ruby的xcodeproj 來修改工程文件,根據設定好的依賴關係指定header search path或user header search paths。這樣,當不在header search path目錄下的文件被import時,編譯器是會找不到的。orm