All things iOS & Swift

Using Cocoapods with Swift

Cocoapods is a popular dependency platform, a walmart of frameworks, it has thousands of libraries and can help you scale up your projects elegantly. Here’s a simple step on setting it up with swift.

    • to install cocoapods, open Terminal and type
      sudo gem install cocoapods
    • type in your computer password and wait for couple of minutes.
    • after that, run setup
      pod setup
    • when you are done, open Xcode and create a single view application
    • now you need to enable it, close xcode for cocoapods to make some modifications in it
      cd <project directory>
    • once you’re inside the project directory, we’ll create a cocoapods file, type in
      nano Podfile
      Screenshot 2015-02-12 02.09.11
    • you need your platform that your apps going to be running on in this file, type the following
      platform :ios, ‘8.0’
    • next is add your pods, we’re going to use AFNetworking and its version for example
      pod ‘AFNetworking’, ‘-> 2.0’
    • it should look like this
      Screenshot 2015-02-12 02.19.49
    • now save and get out of nano by, ctrl + y, and it will ask you if you want to save, press y then press enter.
      If you open your project folder you’ll see a file named Podfile
      Screenshot 2015-02-12 02.19.35
    • the last we’re going to do to run this command
      pod install
      Screenshot 2015-02-12 02.26.13
    • If you go back to your project folder, you’ll see new files and folders, open podsExample.xcworkspaceScreenshot 2015-02-12 02.43.04
    • you’ll see two dependencies when you open the file, podsExample and PodsScreenshot 2015-02-12 02.44.33
    • next, to make your pods accessible to the project, most pods are written in objective-C, we create a linking header, to create a linking header, create new file, C file. any file name will do, after creating, delete this two files.Screenshot 2015-02-12 02.50.49
    • last thing is type import “AFNetworking.h” inside podsExample-Bridging-Header.hScreenshot 2015-02-12 02.52.39

Leave A Comment

Your email address will not be published.