xcode 导入另一个工程

来源:互联网 发布:php 获取当前服务器ip 编辑:程序博客网 时间:2024/05/18 15:28
 转:http://blog.sina.com.cn/u/1509658847
 
参考的所有网址:(喜欢捣鼓的,最好看看那)
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/


下面属于随手笔记,还未好好整理,逻辑较混乱,仅供参考


在自己工程导入另一个工程,有点像导入静态库,只是有点像,如下图:
最好先学会静态库的生成,会很有帮助。

xcode <wbr>导入另一个工程

参考网址:http://www.xiaojiayi.com/2012/08/15/xcode中的子项目(译文)/

上面的文章有几点说的不是很到位,下面解释一下:
1.关于头文件的引入问题,上面的网址使用的方法是:
在工程的"Build Settings"里面使用搜索栏,搜索"User Header Search Paths",添入"recursive"
这种方法要求,子工程的文件夹 要放在 主工程文件夹下面,recursive就是再主工程文件夹下递归查找。

如果子工程文件 与 主工程文件夹 不是相互包含的关系,则上面的设置无效。
应该用如下方法代替:
在工程的"Build Settings"里面使用搜索栏,搜索"Header Search Paths",
添入子工程文件夹的绝对路径,就像“**子工程文件夹”。

2.对于子工程,如果在子工程文件夹下里面自己又乱建其它文件夹的话,这些自己建的文件夹下面的头文件都查找不到,要在上面的基础上,在加设置,添加 递归查找子文件夹

xcode <wbr>导入另一个工程

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_loadoption 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


0 0
原创粉丝点击