Using CocoaPods with Swift

First of all I would say that after fighting to install libraries and frameworks in xcode, the discovery of cocoapods was a huge relief. CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. Through a few command line, you can install cocoapods in your project and install libraries with just one line of code in a podfile. The library will then be managed by cocoapod, which will take care of updating it if necessary. Here is the ressources I have been using to set it up properly:

All this can be resumed in a few simple steps:

    1. get cocoapods through:
      sudo gem install cocoapods
    2. run pod setup:
      pod setup --verbose
    3. navigate to your project directory and run pod init:
      pod init
    4. in your project directory create a new podfile, either manually or through command line:
      open -a Xcode Podfile
    5. Replace the commented code in the podfile with the following lines, and add the framework you want to install (TSMessage here):
      platform :ios, "8.0"
      use_frameworks!
      pod 'TSMessage', '1.2.3' //if you don't specify a version, cocoapod will automatically keep the framework updated to the last version
    6. run pod install to install the dependencies of this framework (and every time you wish to import a new framework, just add the line in the podfile and run pod install again):
      pod install
    7. close xcode and open the newly created yourproject.xcworkspace. Remember that from now on, you MUST always work in .xcworkspace
    8. create a bridging header in which to put a link to the framework header
    9. If you run into an error message from xcode saying “unresolved identifiers” while trying to use a class from the framework you just imported don’t worry, I got the same issue and after (a lot of) googling, I found out this nice article which explain that you should just add:
      import framework_name //framework_name being the name of your framework

      at the top of your class, and you’re good to go!