2

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' 

2 Answers 2

4

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: enter image description here

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

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.

3 Comments

Thank you! My question is more about how I can call the classes of my Pods in xcode. There is a little tutorial for SwiftCSV and I tried it, but it gives me an error, because it cannot find the class (in my case called CSV). After i run "pod install" don't I have to import anything into my xcode Project?
I just update my pod with you package and put import SwiftCSV and works fine!!!
ok.. so there is hope! thank you! I delete everything and try it again.