xcode 匯入另一個工程
參考的所有網址:(喜歡搗鼓的,最好看看那)
http://www.cnblogs.com/xiaodao/archive/2012/03/28/2422091.html
http://www.xiaojiayi.com/2012/08/15/xcode中的子專案(譯文)/
http://blog.csdn.net/liutao6982/article/details/6928486
http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/
http://developer.apple.com/library/mac/#qa/qa1490/_index.html
http://kongbei888.blog.163.com/blog/static/24326613201307111415481/
下面屬於隨手筆記,還未好好整理,邏輯較混亂,僅供參考
在自己工程匯入另一個工程,有點像匯入靜態庫,只是有點像,如下圖:
最好先學會靜態庫的生成,會很有幫助。
參考網址:http://www.xiaojiayi.com/2012/08/15/xcode中的子專案(譯文)/
上面的文章有幾點說的不是很到位,下面解釋一下:
1.關於標頭檔案的引入問題,上面的網址使用的方法是:
在工程的"Build Settings"裡面使用搜索欄,搜尋"User Header Search Paths",添入"recursive"
這種方法要求,子工程的資料夾 要放在 主工程資料夾下面,recursive就是再主工程資料夾下遞迴查詢。
如果子工程檔案 與 主工程資料夾 不是相互包含的關係,則上面的設定無效。
應該用如下方法代替:
在工程的"Build Settings"裡面使用搜索欄,搜尋"Header Search Paths",
添入子工程資料夾的絕對路徑,就像“**子工程資料夾”。
2.對於子工程,如果在子工程資料夾下里面自己又亂建其它資料夾的話,這些自己建的資料夾下面的標頭檔案都查詢不到,要在上面的基礎上,在加設定,新增 遞迴查詢子資料夾
3.Header search paths 設定的另一種方法
設定為 $(BUILT_PRODUCTS_DIR)/include
這個路徑會根據 debug 和release模式不同而不同,
同時,在子專案的 "build phases" 裡面的“copy file”裡面,把所有的標頭檔案都加上。
注意
1.
Other Linker Flags
build
setting under the Linking collection and set its value to -ObjC
.參考連線:http://developer.apple.com/library/mac/#qa/qa1490/_index.html
the target linking against the static library must pass the
-ObjC
option
to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category
Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC
from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -all_load
or -force_load
flags.
-all_load
forces the linker to load all object files from every archive it sees, even those without Objective-C code. -force_load
is available in Xcode 3.2 and later. It allows finer grain control of archive loading. Each -force_load
option
must be followed by a path to an archive, and every object file in that archive will be loaded.
2.“User Header Search Paths” 和 “Header Search Paths”
參考連結:http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/
User Header Search Paths set
The “User Header Search Paths” setting defines the headers available as quoted imports (eg “#import “MyLibraryClass.h”) while the “Header Search Paths” setting defines those headers available as bracketed imports (eg “#import ). I’ve found that Xcode will only autocomplete header names in the quoted form so I always add libraries to the user header search path even though, from my project’s perspective, they might be more appropriate as system level (angle bracketed) libraries.
When using a static library which includes categories we will also have to add the “-ObjC” flag to the “Other Linker Flags” build setting. This will force the linker to load all objective-c classes and categories from the library. If the library contains only categories “-all_load” or “-force_load” may be needed as well. See Technical Q&A QA1490 for a more detailed explanation of these settings.3.注意:在ios5以及以上版本中,引入別的工程(如上)或者靜態庫,
並且StoryBoards中使用了【引入的外部類(外部工程或者靜態庫裡面的類)】,
那麼
Other Linker Flags 裡面必須加上-ObjC,否則,會console會報錯
error:Unknown class <外部的類名> in Interface Builder file.
引用:
http://developer.apple.com/library/mac/#qa/qa1490/_index.html
-ObjC,This flag causes the linker to load every object file in the library that defines an
Objective-C class or category
意思是,使用這個標識,會把靜態庫中,定義了Objective-C class的檔案或者定義了category類別的檔案,全部載入進來。
因為你的靜態庫裡面擴充套件了一個已存在的類的category,那麼這個category是不會載入進來的。
在程式執行中,呼叫此類別的方法,就會報錯“selector not recognized”。
Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents
-ObjC from loading objects files from static libraries that contain
only categories and no classes. The workaround is to use the -all_load
or -force_load
flags.
上面的意思是說
對於64位作業系統或者ios系統,-Objc存在一個bug,就是隻包含categories ,而沒有任何class的靜態庫,是不會被載入進來。
拮据額這個bug:使用識別符號:
-all_load 或者 -force_load