- 浏览: 1030936 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (675)
- ios (214)
- android-course (5)
- unity3d (7)
- cocos2d (36)
- html5 (3)
- game (5)
- android (42)
- java (57)
- php (12)
- 创业 (10)
- SEO (3)
- 架构 (2)
- 数据库 (3)
- 产品设计 (9)
- 操作系统 (10)
- Web前端 (11)
- 其他 (50)
- GAE (1)
- mac os (8)
- Open Source (2)
- 序列号 (10)
- C (2)
- database (2)
- 算法 (6)
- 设计模式 (1)
- photoshop (1)
- 3dmax (1)
- maya (1)
- opengl (3)
- 游戏设计 (1)
- 趋势 (1)
- cocos2d-x (4)
- shell (3)
- c++ (30)
- lua (5)
- flash (1)
- spring (3)
- mysql (4)
- Git (6)
- xmpp (1)
- cocos2dx (14)
- mac (2)
- 编程规范 (2)
- windows (1)
- linux (5)
- coocs2dx (1)
- ubuntu (2)
- aws (1)
- OPENGLES (1)
- 原画 (1)
最新评论
-
jlees:
Best mobile app testing tool pc ...
iOS + XCode 4 + GHUnit = Mobile TDD+Continuous testing -
ipanda:
楼主,能否给一个Micro CloudFoundry的虚机或者 ...
Cloud Foundry使用及开发向导 -
love_zongming:
谢谢分享。。
visio2007序列号 -
雨花台舞水:
你这才是枪文把
套在 360 黑匣子外面的黑盒子:你被技术型枪稿吓到了么? -
hugh.wang:
改天试试
Mac版魔兽争霸3 1.24e下载
Xcode 4.0.1 allows us to more easily create and use third party libraries in iOS projects. I think the process is still more complicated than it needs to be. Xcode’s documentation suggests that it should automatically detect implicit dependencies and index classes across workspaces but I have not found this to be the case. Here I’ll cover the steps I have found for creating and sharing code between projects and with other developers.
Background
Workspaces:
Xcode 4 introduced the concept of workspaces as containers for multiple projects. There are a couple of key behaviors of workspaces which we want to build on when choosing how to share code across projects.
- By default, all the Xcode projects in a workspace are built in the same directory, referred to as the workspace build directory.
- Xcode examines the files in the build directory to discover implicit dependencies.
- Each project in a workspace continues to have its own independent identity.
Schemes:
Within a workspace or within a project which is a member of a workspace we have schemes. Schemes replace the Active Target, Build Configuration, and Executable settings from Xcode 3 and define which targets to build, the order in which to build them, and what action to take when a build is complete. We’ll want our shared code to easily fit into the scheme of any projects which use it. The Xcode 4 Transition Guide covers this new structure in more detail.
Targets:
Within a scheme we have one or more build targets which define a set of source files to build, the settings used to build those files, and any dependencies on the build products of other targets which must be completed first. Ultimately we would like a consumer of our code to be able to state that their project’s build target depends on our shared code and have Xcode build this shared code and make it available to the active build target. We can achieve that by providing a project containing the code to be shared and a static library build target which packages it into a build product other developers can add as a build target dependency.
Using a static library
- Creating a workspace
- Adding projects to a workspace
- Adding build target dependencies
- Adding the static library’s headers
- Configuring the project’s scheme
- Fixing indexing
Creating a workspace
We can create a new empty workspace from Xcode’s file menu or open an existing project and select “Save As Workspace…” to create a new workspace containing our project. This will create a “.xcworkspace” package in the file system.
Adding projects to a workspace
Once we have a workspace we can right-click in the workspace’s navigator to create a new project or add an existing “.xcodeproj” package.
We want to end up with a single workspace containing our app’s project and the projects for any static libraries we are going to depend on. It is worth noting that these projects are all siblings in the workspace, our static libraries are not added as references within our app’s project.
Adding build target dependencies
With all of the projects we need available in our workspace we can select our app’s build target and add a static library to the “Link Binary With Libraries” build phase.
Adding the static library’s headers
We also need to make sure that our app’s build target can locate the public headers used in this static library. Open the “Build Settings” tab and locate the “User Header Search Paths” setting. Set this to “$(BUILT_PRODUCTS_DIR)” (or “$(BUILT_PRODUCTS_DIR)/static_library_name” if we want to be more specific but then we’ll have to update this setting every time we add another library) and check the “Recursive” check box. Now our built target will search our workspace’s shared build directory to locate linkable header files.
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.
Configuring the project’s scheme
At this point Xcode should have detected this implicit dependency between our app’s project and the static library’s project and have automatically configured our schemes correctly. Unfortunately I haven’t found this to be the case in practice. Instead we will have to edit our current scheme and add the static library’s build target before our app’s build target.
Fixing indexing
At this point we should be able to include headers from dependent static libraries, use the included classes, and still successfully build our app. Unfortunately Xcode will not show any classes from these linked static libraries in code completion despite the workspace documentation stating that “indexing is done across the entire workspace, extending the scope of content-aware features such as code completion and refactoring.”
As a workaround we can drag the public headers from the static library’s project into our app’s project, adding them as references. These headers do not need to be included in any of our build targets, simply having references to the headers in our project will allow their classes to appear in code completion.
Creating a Static Library
If we plan on releasing some of our own code for reuse as a static library there are several things we should do to make sure that the process described above is as easy and simple as possible for our library’s users.
- Namespace classes appropriately
- Create a build target
- Expose public headers
- Set the installation directory
- Set the public header path
- Exclude user specific files from VCS
Namespace classes appropriately
Use an appropriate prefix for classes, protocols, functions, and constants in the library to prevent collisions with names in the library’s user’s project.
Create a build target
Provide a static library build target in the project for our users to link against. Xcode provides templates for creating projects with static libraries or adding static library build targets to existing projects.
Expose public headers
Determine which header files should be visible to users of the library. Provide a clearly named group containing these headers so that our library’s users can easily locate them as part of the workaround described in “Fixing Indexing” above. This also helps us clarify what the public interface our library provides is and what classes are implementation details which are likely to change as the library evolves.
For each public header file make sure it is set as “public” in the “Target Membership” section of the inspector pane. Only public headers are going to be available for our users to import.
Set installation directory
Our static library build target is going to be a member of a user’s workspace and subject to that workspace’s installation rules. Our static library build product could therefore be installed in a location set by Xcode’s preferences, in the derived data path, or in a path specified by our build target. Since we can’t control the user’s settings we should make sure our library is well behaved in all cases. I set the “Installation Directory” build setting to “$(BUILT_PRODUCTS_DIR)” so that the static library build product can be found in a known location and set the “Skip Install” build setting to “Yes” to avoid accidentally installing iOS libraries into “/usr/local/lib”.
Set the public header path
We need to specify a location to copy our static library’s public headers to so that they can be included in our users’ header search paths. Setting the “Public Headers Folder Path” to “$(TARGET_NAME)” will create a folder named after our static library build target in the workspace’s shared build directory and be indexed by the “User Header Search Paths” setting described above.
Exclude user specific files from VCS
Our workspace and project include a number of files which contain data relevant only to our user account; window positions, open files, and so on. There’s no need to check these into source control, at least not in our release branch, so let’s set some reasonable ignore rules in git or whatever VCS we are using. Github provides a convenient set of .gitignore files
Future Improvements
Hopefully Xcode 4 will eventually live up to the promise of it’s documentation and consistently auto-detect implicit dependencies and index files across the workspace correctly. There certainly seem to be a number of other developers struggling with this behavior:[1], [2], [3], [4], [5], [6], [7], [8]. Until that indexing improves I find that this process is at least somewhat simpler and cleaner than trying to maintain simulator and device compatible static library builds in Xcode 3.
I’ve found this pattern preferable to copying third party classes directly into my projects as it allows me to easily keep version history and make updates to static library projects in my workspace and avoids coupling my project too closely to the private structure and contents of the static library.
Please let me know if you can see any areas where this pattern could be improved or if you’ve found your own alternative means of sharing code.
转载:http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/
发表评论
-
Mac上安装Protocol Buffers
2016-09-18 11:29 8191.下载文件 (http://code.google.com ... -
webview点击获取图片
2016-04-01 17:12 827UILongPressGestureRecognizer * ... -
hexo 自动部署脚步
2016-03-29 21:17 932echo "===============star ... -
自定义navigationItem.leftBarButtonItem后,系统默认的手势滑动失效解决方案
2016-03-01 18:01 1280自定义navigationItem.le ... -
UITextView autolayout 高度自适应
2016-02-15 23:26 1413UITextView *t = [[UITextView ... -
腾讯敏捷框架TAPD》研究
2015-11-19 20:47 1420这篇文档是研究心得 ... -
ios image 压缩
2015-11-06 12:09 837- (UIImage *)_scaleToSize:(UII ... -
iphone分辨率图解
2015-11-04 17:33 565iphone分辨率图解 -
IOS中获取各种文件的目录路径的方法
2015-09-24 12:10 647iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储 ... -
Customizing Navigation Bar and Status Bar in iOS 7
2015-08-17 20:23 1606Like many of you, I have been ... -
GCD 深入理解:第一部分
2015-07-24 14:49 767本文翻译自 http://www.raywenderlich ... -
Mac上的抓包工具Charles
2015-05-06 01:09 5316Mac上的抓包工具Charles 分类: IO ... -
如何移除发布版本中的NSLog输出
2015-05-04 20:27 749Phone开发中会经常使用NSLog将一些运行信息输出到终端 ... -
xcode4的环境变量,Build Settings参数,workspace及联编设置
2015-03-27 11:23 924一、xcode4中的环境变量 $(BUILT_PROD ... -
数字签名是什么?
2014-11-25 16:58 616http://www.ruanyifeng.com/blog/ ... -
让你的Xcode更加高效
2014-10-29 00:16 518http://www.tairan.com/archives/ ... -
我所经历的“余额宝”的那些故事
2014-06-08 01:05 758“余额宝”经过不到 ... -
代码手写UI,xib和StoryBoard间的博弈,以及Interface Builder的一些小技巧
2014-05-31 01:25 794最近接触了几个刚入门的iOS学习者,他们之中存在一个普遍 ... -
WWDC 2013 Session笔记 - iOS7中的多任务
2014-05-31 01:24 661这是我的WWDC2013系列笔记中的一篇,完整的笔记列表 ... -
APP被苹果App Store拒绝的79个原因(未完待续)
2014-05-09 10:49 1147作为iOS开发者,估计有很多都遇到过APP提交到App Sto ...
相关推荐
The dramatic growth in open source software libraries has made the GRASS6 development more efficient, and has enhanced GRASS interoperability with a wide range of open source and proprietary ...
The dramatic growth in open source software libraries has made the GRASS6 development more efficient, and has enhanced GRASS interoperability with a wide range of open source and proprietary ...
The dramatic growth in open source software libraries has made the GRASS6 development more efficient, and has enhanced GRASS interoperability with a wide range of open source and proprietary ...
The dramatic growth in open source software libraries has made the GRASS6 development more efficient, and has enhanced GRASS interoperability with a wide range of open source and proprietary ...
GitNux is an open source Github app that lets you access your Github profile, repositories, starred, projects and codes. Features Show your profile overview See your follower's project/repositories ...
3. **解压Qtopia源码**:将下载的qtopia-opensource-src-4.2.3.tar.gz解压缩,并将内容移动到`source`文件夹中。 4. **编辑qmake.conf**:进入`source/mkspecs/qws/Linux-arm-g++`目录,使用gedit编辑qmake.conf。...
在这个“FFmpeg 4.2.2 static libraries for macOS.rar”压缩包中,包含了FFmpeg在macOS平台上的静态库文件,非常适合开发者在构建自己的多媒体应用时使用,如播放器、视频剪辑工具或视频下载工具。 1. **FFmpeg ...
penFOAM基础--编译applications和libraries openFOAM是一个库,用户在编程时需要调用此库,当然用的语言是面向对象的c++语言。在使用openFOAM时我们应该将关注点放在顶层使用类以及数值算法上,这就需要对openFOAM...
Altium开源库Altium Designer的开源库包括各种组件,模块等##如何使用在每个库文件夹中,您将找到以下一个或多个文件类型: .SchLib(库的原理图部分) .PcbLib(库中组件的封装) .LibPkg(库项目,如果要修改它...
Using the C++ Standard Template Libraries 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权...
and blockchain enthusiasts who want to build powerful, robust, and optimized smart contracts using solidity from scratch and in combination with other open source JavaScript libraries. If you want to...
How to take advantage of Xcode's vast libraries, frameworks and bundles How to create exciting interactive apps for iPhone or iPad using Sprite Kit, Map Kit, and other Apple technologies How to share ...
在C++编程中,动态库(Dynamic Libraries)和静态库(Static Libraries)是两种常见的代码复用方式。模板(Templates)则是一种强大的泛型编程工具,允许我们在编译时创建类型安全的通用代码。理解如何在动态库和...
The POCO C++ Libraries are... > a collection of C++ class libraries, ...> Open Source, licensed under the Boost Software License, > and thus completely free for both commercial and noncommercial use.
Xcode 5 Start to Finish will help you use the tools in Apple’s Xcode 5 to improve productivity, write great code, and leverage the newest iOS 7 and OS X Mavericks features. Drawing on thirty years ...