Adding a simple library to an xcode 4 project

I know this is a very simple question, but I'm struggling a bit with it. I read a few topics, but can still find the answer.

I am trying to add this DDMathParser library to my existing project. In the math analyzer documentation

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

I added a subfolder to my project and added the `#import 'DDMathParser.h' header to my first view controller. At first, Xcode claimed that it could not find the file. I took advice from another thread and changed my title to include a folder

#import "DDMathParser/DDMathParser.h" 

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

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

I get the error message "Thread 1: received sginal program:" SIGABRT "" I see in the sample DDMathParser file that there is a goal, I wonder if this is my problem.

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

+6
source share
2 answers

First, do not add DDMathParser code to your project through a copy of the subfolder. This will lead to pain in order to easily receive any future code updates, and overall this is not a good approach to include external code in your projects.

Instead, you should add the git repository as a submodule of your project (you use git, right?) And import the appropriate files into your project. Here's a step by step solution:

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

Now DDMathParser works as you expect. If the author comes out with a code update, you can simply issue the following command from the terminal to pull the latest updates from github: git submodule update .

Note. I created a new project from scratch, performed the following steps, and included the NSLog() example to make sure there were no problems.

+12
source

I also followed these steps until I was able to get it to work. The proposed method has some disadvantages.

  • As I had a guy in front of me --- you just bring the DDMathParser SOURCES, and compile them as part of your goal. This bundles you must use the same build settings, SDK version and deployment as the DDMathParser version. Examples:

    • didn't use ARC for my purpose --- now I have to.
    • I planned to use the MacOS 10.8 SDK in my project (for many reasons), but I had a strange ARC compilation error in one source DDMathParser, which disappeared only after I switched to SDK 10.9 (the version used by the author in his samples and documents )
    • I MUST provide my application for MacOS 10.8 and higher, now I'm not sure if it will work.
  • I do not know what will happen if I pulled the parent repo to the server, and the other pulls it. Will it get the DDMathParser repo automatically? How? He must have access to him! This scheme does not seem complete to me.

I suggest helping the author pack his DDMathParser as a framework, and then you can import the PROJECT FILE of DDMAthParser into your project --- not sources and just reference the DDMathParser project product (private structure). It seems a lot nicer. The framework can be compiled using the author’s settings, and we just get a beautifully packaged binary.

0
source

Source: https://habr.com/ru/post/894496/


All Articles