How to include a Library into my Swift Project? How to include a Library into my Swift Project? xcode xcode

How to include a Library into my Swift Project?


The best way to import third-party dependencies is via dependency managers: CocoaPods/Carthage/SPM, you will be able to update a lib without headache.

1. CocoaPods [Offical Guide]

This is by far the easiest way to go...

Open terminal

Install CocoaPods (type in terminal):

sudo gem install cocoapods

Sudo means "super user do", it will require your password. Enter when requested.

Next, you need to setup the cocoapods master repo. Type in terminal:

pod setup --verbose // verbose option logs the setup progress

then create a pod file in your project directory (you can type "cd " and drag the project folder to the terminal window if your not comfortable with writing the path):

cd User/Projects/YourProject // make way to your project dirpod init 

then inside the Podfile (find it in project directory) insert:

platform :ios, '8.0'use_frameworks!target 'YouAppTarget' do    pod 'CSVImporter', '~> 1.7'end

(Uncomment platform :ios, '8.0' Uncomment user_frameworks! if you're using Swift)

Run (while in your project dir):

pod install

Xcode .xcworkspace file will be generated, thats it, you can open it and use the framework ;]

later on you can update lib with:

pod update

2. Carthage [Offical Guide]

Steps to install a framework via Carthage are pretty similar to CocoaPods, follow the 'Offical Guide' link to see what's the differences are. A downside about this dependency manager is that not all libs are available. Some are only available for CocoaPods, but majority of new ones are supporting Carthage.P.S. Here's a good article on the differences.

3. Swift Package Manager [Offical Overview/Guide]

SPM is a native dependency manager, it's cross-platform, officaly-supported by Apple, decentralized and open-source.

It was planned as a replacement for CocoaPods and Carthage so I'd give it a try too.


You can drag the CSVImporter.xcodeproj and drop it into your project, also include CSVImporter in the embedded binaries.