部分Xcode资料--xcode 导入另一个工程

来源:互联网 发布:js 过滤前后空格 编辑:程序博客网 时间:2024/05/16 08:18
/*
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_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
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 床垫外面布坏了怎么办 淘宝店铺动态评分低怎么办 实创倒闭返款怎么办 qq红包忘记支付密码怎么办 qq红包支付密码忘了怎么办 个人卖东西人家要发票怎么办 打了欠条找不到人怎么办 公章掉进水里了怎么办 手游吃鸡限制登入15分钟怎么办 宝宝的小鸡淹了怎么办 宝宝小鸡底下淹了怎么办 4岁宝宝拉稀水怎么办 2岁半宝宝对眼怎么办 孩子在幼儿园中午不睡觉怎么办 20天婴儿拉稀水怎么办 3个月婴儿拉水怎么办 两岁宝宝拉水怎么办 1岁半宝宝拉水怎么办 5周孩子小鸡长脂肪粒怎么办 小孩丁丁长歪了怎么办 2个月的婴儿咳嗽怎么办 2个月的宝宝干咳怎么办 2月宝宝感冒咳嗽怎么办 产妇肚子上长小疙瘩很痒怎么办 泰迪生下小狗不吃奶怎么办? 刚生的狗不吃奶怎么办 刚出生的小牛不吃奶怎么办 吃奶的狗崽拉稀怎么办 新生儿吃奶老是呛到怎么办 刚生小狗不吃奶怎么办 刚出生的小羊不吃奶怎么办 羔羊走路不稳不吃奶怎么办 新生儿喝奶老是呛到怎么办 宝宝吃母乳呛到怎么办 宝宝一直睡觉不吃奶怎么办 3个月婴儿不吃奶怎么办 新生婴儿晚上不睡觉怎么办 宝宝肚子胀不吃奶怎么办 宝宝25天不睡觉怎么办 50天婴儿不吃奶怎么办 儿子关在房间玩电脑怎么办?