开发者

Xcode & iPhone - Best way for reusing code within multiple projects?

What is the best way to reuse code within projects?

Let's say I im开发者_StackOverflow社区plemented a UI Element and I want it to be used in both my iphone and ipad application without having to copy the code over and have 2 copies of it.


Just create a project, which includes all your shared code in XCode and reference this project in your iPhone and iPad application project. Plain and simple.


For me I would make a static library project which contains the shared code (UI Element in your example) in Xcode.

Then when I need to use the library in the iPhone or iPad app project, then I can just reference the static library project by drag and drop the project to the Project Navigator and configure the correct dependency, library used and header search path. In this way you always have a single source of library source code for easier maintenance and modification.

Certainly you can actually compile the static library into binary and link it to your project, but it just not too flexible when you find bugs in your static library and need to switch to another project to correct the bug, and then do the compile and copy of the binary library file.

I have just wrote an article (link below) on how to link up the static library project to an iOS project on Xcode 4.3.2. This maybe useful for you to solve the header not found problem you encountered. Hope this help.

http://vicidi.wordpress.com/2012/04/11/linking-an-ios-static-library-project-in-another-project-in-xcode-4-3-2/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜