将一个简单的库添加到xcode 4项目中 [英] adding a simple library to an xcode 4 project

查看:118
本文介绍了将一个简单的库添加到xcode 4项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个非常简单的问题,但我一直在努力解决它。我已经阅读了几个主题,但似乎仍然可以找到答案。

I know this is a very simple question but I have been struggling with it for a while. I have read a few threads but still can seem to find the answer.

我正在尝试添加此 DDMathParser 库到我现有的项目。数学解析器文档说明

I am trying to add this DDMathParser library to my existing project. The math parser documentation states

只需​​将DDMathParser子文件夹复制到项目中,#importDDMathParser.h,你就可以了。

"Simply copy the "DDMathParser" subfolder into your project, #import "DDMathParser.h", and you're good to go."

我将子文件夹添加到我的项目中,并将标题#importDDMathParser.h'添加到我的第一个视图控制器中。首先,Xcode声明它无法找到我接受了另一个线程的建议并更改了我的标题以包含文件夹

I added the subfolder to my project and added the header `#import "DDMathParser.h' to my first view controller. At first Xcode was stating that it can't find the file. I took the advice from another thread and changed my header to include the folder

#import "DDMathParser/DDMathParser.h"

Xcode似乎找到了文件夹和头文件但是当我从文档中运行测试时如

Xcode seems to find the folder and header file but when I run a test from the documentation such as

NSLog(@"%@", [@"1 + 2" numberByEvaluatingString]);

我收到错误'Thread 1:Program received sginal:SIGABRT'我可以在DDMathParser示例文件中看到有一个目标,我想知道这是否是我的问题。

I am getting the error 'Thread 1: Program received sginal: "SIGABRT"' I can see in the DDMathParser sample file that there is a target, I am wondering if this is my problem.

澄清问题我试图添加 DDMathParser 库到一个简单的视图控制器并运行staement NSLog(@%@, [@1 + 2numberByEvaluatingString]);
如果有任何帮助/澄清,我们将不胜感激。

To clarify the question I am trying to add the DDMathParser library to a simple view controller and run the staement NSLog(@"%@", [@"1 + 2" numberByEvaluatingString]); Any help/clarification in doing so would be greatly appreciated.

推荐答案

首先,请不要通过子文件夹副本将DDMathParser代码添加到项目中。这样做会使得轻松获取代码的任何未来更新变得很痛苦,并且通常不是在项目中包含外部代码的非常好的方法。

First, please do not add the DDMathParser code to your project via a subfolder copy. Doing so will make it a pain to easily grab any future updates to the code and in general is not a very good approach to including external code in your projects.

相反,您应该将git repo添加为项目的子模块(您正在使用git,对吧?)并将相关文件导入您的项目。这是一个循序渐进的解决方案:

Instead, you should add the git repo as a submodule of your project (you are using git, right?) and import the relevant files to your project. Here's a step-by-step solution:


  1. 将DDMathParser repo作为子模块添加到项目中。 以下是有关如何添加子模块的说明你的项目目录。看一下这个答案,但为了简洁起见,你将从你项目的根目录中的终端发出这个命令: git submodule add https://github.com/davedelong/DDMathParser.git External / DDMathParser 。这将为项目根目录创建一个名为External的新子目录,在External中将复制DDMathParser项目。

  2. 将DDMathParser目录添加到项目中。它将在< Your Root Project Dir> / External / DDMathParser / DDMathParser 目录中找到。请务必选中添加到目标复选框和以选中复制项目复选框。

  3. 添加 #import DDMathParser.h到你的viewcontroller。

  1. Add the DDMathParser repo as a submodule to your project. Here are instructions on how to add a submodule in your project directory. Take a look at that answer, but for brevity's sake, you'll issue this command from terminal in your project's root directory: git submodule add https://github.com/davedelong/DDMathParser.git External/DDMathParser. This will create a new subdirectory named External to your project root directory and inside External the DDMathParser project will be copied.
  2. Add the DDMathParser directory to your project. It will be found in <Your Root Project Dir>/External/DDMathParser/DDMathParser directory. Be sure to check the "add to targets" checkbox and not to check the "copy items" checkbox.
  3. Add #import "DDMathParser.h" to your viewcontroller.

DDMathParser现在可以正常工作了。如果作者提供了代码更新,您只需从终端发出以下命令即可从github获取最新更新: git submodule update

DDMathParser should now work as you expect. If the author comes out with an update to the code you can just issue the following command from terminal to pull the latest updates from github: git submodule update.

注意:我从头开始创建一个新项目,按照这些步骤并包含你的 NSLog()示例以确保没有任何问题。

Note: I created a new project from scratch, followed these steps and included your NSLog() example to ensure that there aren't any issues.

这篇关于将一个简单的库添加到xcode 4项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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