Import Function from a Pod - CoCoaPods Swift

0

I'm now starting with Swift (Xcode 7), I installed cocoapods, but wanted to know how to import the functions that exist in the pod to a new project.

    
asked by anonymous 09.06.2016 / 21:15

1 answer

0
  • Create a new project in XCode. Close XCode.
  • Open the terminal and navigate to the project folder
  • Type pod init and give enter. This will create a file named Podfile . Open this file in any editor.
  • The file structure looks something like this:

    platform :ios, '9.0'
    use_frameworks!
    
    target 'MyApp' do
    
    end
    
  • Swap 'MyApp' by the name of your app project

  • Between do and end , put the libraries you want to use this way (I'll put 3 libraries as an example):

    target 'MyApp' do
        pod 'Alamofire'
        pod 'PKRevealController'
        pod 'SwiftyJSON'
    end
    
  • Close the file, return to the terminal and type pod install
  • When the program finishes downloading and configuring everything, it will create a file named <NomeDoSeuProjeto>.xcworkspace . Open this file. From now on, just move the project from that workspace. If you open the project by yourself (as you normally do), the libraries will not be there and XCode will not be able to build your project. A workspace is just a project that brings together several projects in one, to make our life easier.
  • On the left side, in the projects / files tab, your project will appear and an extra project, where the libraries you downloaded will be installed.
  • Cocoapods sets up the link automatically, just import the libraries (this is very important, you need to explicitly import the libraries you have installed) into your code and use it normally.
  • XCode may not recognize the library and issue an error when you first import it. Just give build (Command-B) this is fixed.
  • 12.06.2016 / 08:15