简体   繁体   中英

Import CocoaPods (Swift) to Xcode Project

I would like to use a Cocoa Podfile called SwiftCSV , as I understand it is already written in Swift.

I would now like to import this in my class but I cannot figure out how I have to do it. Can anyone relate to that?

This is my Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'SwiftCSV'

I had the exact same problem. I futzed around with the helper files and so on until I found that pod install did not install the frameworks correctly. I added the framework manually, then it worked.

So do the Podfile, pod install , use the ".xcworkspace" project - this is CocoaPods 101 - and then the steps below

My Podfile:

use_frameworks!
pod "SwiftCSV"

1 - Make sure the framework is linked in the project/target.

  • Click on the project -> Target -> General -> Linked Frameworks and Libraries and hit "+"
  • Add the SwiftCSV.framework. Pods.framework was already added for me, so I guess pod install did that part correctly.

2 - In the swift file that wants to use SwiftCSV:

import Foundation
import SwiftCSV  // <===== I had to add this

class SomeClassThatUsesSwiftCSV {
  var foo: CSV?
}

For verification, make sure your project "Frameworks" group looks like this: 在此处输入图片说明

Note: I am new to CocoaPods but I would expect that pod install does all this for me. That's the whole point of it, isn't it? But, it didn't, at least for me.

When you want to know how is the line you have to put to import a library using Cocoapods I strongly recommend you go to https://cocoapods.org/ an put the name of the package you want and then you will see the line you need to put in your pod file if the package is available for Cocoapods of course.

For your package https://cocoapods.org/?q=SwiftCSV you have to put the following line :

pod 'SwiftCSV', '~> 0.1'

When starting out with a project it is likely that you will want to use the latest version of a Pod. If this is the case, simply omit the version requirements as you do it in you above pod.

You can read more about it the Podfile in the Cocoapods guides

Then you have go to the directory where your pod file is and run in the console pod install .

And to use the library you want just put import SwiftCSV wherever you want to use it.

I hope this help you.

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