如何在Xcode中创建一组可重用的代码? [英] How do I create a bundle of reusable code in Xcode?

查看:96
本文介绍了如何在Xcode中创建一组可重用的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPhone应用程序,并且必须解析xml文件才能将它们放入数据库中。我还将在我的应用程序中使用相同的xml解析器,以便用户可以导入自己的数据。我想知道如何将这些xml解析器提取到一个包或一个库中,这样我就可以在我的iPhone应用程序和命令行应用程序中使用它们,我只是填充一个sqlite3数据库。

I am developing an iPhone app and have to parse xml files in order to put them into a database. I will also be using those same xml parsers in my app so users can import their own data. I was wondering how I can extract those xml parsers into a bundle or a library so I can use them both in my iPhone app and in a command line app where I just populate a sqlite3 database.

提前致谢!

推荐答案

创建一个静态库项目,然后使用Xcode的项目间依赖项功能来构建它们按正确的顺序排列,并将应用程序与静态库链接。您需要为所有项目设置一个公共构建目录才能使其正常工作(至少您在Xcode 3.0周围做过,没有检查这是否仍然是3.1的问题。)

Create a static library project, then use the interproject dependency feature of Xcode to build them in the correct order and link the app with the static library. You'll need to have a common build directory set for all the projects for this to work correctly (at least you did around Xcode 3.0, didn't check if this is still a problem with 3.1).

您可以从目标或项目的构建设置(在获取信息窗格中)设置构建目录。要创建插图依赖项:

You can set the build directory from the target or project's build settings (in the Get Info pane). To create an interpoject dependency:


  • 将库项目拖到应用程序项目的Files& 组窗格。

  • 在应用程序目标的获取信息窗格中设置目标依赖项。使其依赖于库的目标。

  • 在应用程序目标的链接到库步骤中拖动库产品。您可以通过在应用程序项目的文件和扩展中扩展库项目来查找库产品。小组(点击箭头)。

听起来比这更复杂。它并不多。

Sounds more complicated than it is. It isn't much.

(小额外:是的,您需要一个公共构建文件夹,如 Xcode项目管理指南,以及 Xcode构建系统指南可以帮助您获取Xcode的构建系统,其中 - 以开始宗教战争为代价 - 我认为这是最灵活,最简单的构建系统之一。)

(Small extras: yes, you need a common build folder as indicated in the Xcode Project Management Guide, and the Xcode Build System Guide can help you "get" Xcode's build system, which -- at the cost of starting a religion war -- I think is one of the most flexible and simple build systems out there.)

这篇关于如何在Xcode中创建一组可重用的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆