简体   繁体   中英

How to import a third-party framework into my Swift project?

I am trying to import the DDMathParser framework into my Swift app. I tried following the installation instructions from the DDMathParser wiki, though it did not work:

DDMathParser is packaged as a Swift framework.

Add DDMathParser.xcodeproj to your workspace and link MathParser.framework into your app.

(Link: https://github.com/davedelong/DDMathParser/wiki/Installing )

Here's what I did:

  1. I dragged in the .xcodeproj file into my project (from Finder to Xcode), and the file shows up under my project in the sidebar.
  2. I went to my project settings and clicked the '+' under "Linked Frameworks and Libraries" and neither "MathParser.framework" or "DDMathParser.framework" are showing up in the list of available frameworks.
  3. I tried building my application after adding the xcodeproj, but the framework files are still not showing up.

What am I doing wrong, or how do I correctly install this framework?

(Using Xcode 7.2.1)

Navigate to your project using the "Terminal app" once at the root folder type pod init a Podfile will be created you can open it with nano Podfile and add these changes with updated paths to your specific project.

source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'YOURPROJECT.xcodeproj'
platform :ios, '9.0'
use_frameworks!

pod 'DDMathParser'

Then save your file.

type pod install and hit enter.

Now open your new .xcworkspace that was created. In any file that you want to use the DDMathParser framework just add import DDMathParser to the top of your file.

1) $ sudo gem install cocoapods (gem will get installed in Ruby inside System library)

2) create a xcode project

3) Open terminal

4) cd "path to your project root directory"

5) pod init

6) open -e podfile (podfile will get open in text mode. Initially it will be emppty put the follwoing line of code.)

7) pod 'DDMathParser' (Cocoapods Podfile name ) // This is example

8) pod install

CocoaPods 0.36 and above will support for swift

Try the following as it helped me a lot of times:

  1. Create a workspace eg. I named it Beacon
  2. Create a project in it eg I create a project named BeaconDemo
  3. Create a Podfile in the folder where you created the workspace
  4. The contents of Podfile :

    workspace 'Beacon'

    xcodeproj 'BeaconDemo/BeaconDemo.xcodeproj'

    platform :ios, '8.0'

    use_frameworks!

    pod 'NearbyMessages', '~> 0.9'

    pod 'EstimoteSDK', '~> 3.8'

    pod 'Charts', '~> 2.2'

    pod 'GoogleMobileAds', '~> 7.6'

  5. Open terminal and go to your workspace

  6. Hit pod install
  7. Then open the workspace that you have created eg over here as in step 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM