adding a simple library to an xcode 4 project

后端 未结 2 573
一向
一向 2020-12-30 14:22

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.

I am trying t

相关标签:
2条回答
  • 2020-12-30 14:56

    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.

    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. 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 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.

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

    0 讨论(0)
  • 2020-12-30 15:02

    I followed these steps too, until I could make it work. The suggested method has some flaws.

    1. As the guy before me had it --- You only bring in the SOURCES of DDMathParser, and compile them as part of your target. This binds you to use the same build-settings, SDK version and deployment system-version as the author of DDMathParser. Examples:

      • didn't use ARC in my target --- now I must.
      • I intended to use MacOS 10.8 SDK in my project (for many good reasons) but I got strange ARC compilation error in one DDMathParser source, that only disappeared as I switched to SDK 10.9 (version used by author in his samples and docs).
      • I MUST provide my application for MacOS 10.8 and above, now I'm unsure it will work
    2. I don't know what happens if I push my parent repo to the server, and another friend pulls it. Will he receive the DDMathParser repo automatically? How? He must have access to it! The scheme does not seem complete to me.

    I will suggest to aid the author in packaging his DDMathParser as a framework, and then you will be able to import the PROJECT FILE of DDMAthParser into your project --- not the sources, and simply link against the product of DDMathParser project (a private framework). Seems much nicer. the framework can be compiled using the author's settings, and we just receive the nicely-packaged binary.

    0 讨论(0)
提交回复
热议问题