How To Add CocoaPods To Project

Developing apps without any third-party code would be extremely time-consuming nowadays. And it’d be like reinventing the wheel once more.

That’s why we can use Dependency Manager like CocoaPods. How does it work? It allows us to use someone’s library like Realm or SwiftyJSON in our project.

Firstly open Terminal and use the command:

sudo gem install cocoapods

Then go to your project folder (RealmProject in this case) and use:

pod install

It will create Podfile where you can put dependency.

Open Podfile with some text editor.

Uncomment platform line and use platform and version you need. If you don’t do that, the highest version will be used.

In the next line add “use_frameworks!” it tells to use Framework instead of Static Library.

Between “target” and “end” you can put libraries names. In this case, we will use RealmSwift.

Then save changes and quit.

Now in the project folder (don’t change your location) run:

pod install

Your folder project looks like this. Then open .xcworkspace.

You can use open command.

At first, Xcode won’t see that dependency, you need to build a project.

After successful, you can use the imported library.

Now you can add as many as you want libraries.