Import a Pod function - Cocoapods Swift

Asked

Viewed 326 times

0

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

1 answer

0


  1. Create a new project in Xcode. Close Xcode.
  2. Open the terminal and navigate to the project folder
  3. Digital pod init and gives enter. This will create a file called Podfile. Open this file in any editor.
  4. The file structure looks something like this:

    platform :ios, '9.0'
    use_frameworks!
    
    target 'MyApp' do
    
    end
    
  5. Barter 'MyApp' by the name of your app project

  6. Between the do and the end, puts 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
    
  7. Close the file, go back to the terminal and type pod install
  8. When the program finishes downloading and configuring everything, it will create a file called <NomeDoSeuProjeto>.xcworkspace. Open this file. From now on, just touch the project from this Workspace. If you open the project yourself (as is usually done), the libraries won’t be there and Xcode won’t be able to build your project. A Workspace is just a project that brings together several projects in one, to make our life easier.
  9. On the left side, in the projects/files tab, your project and an extra project will appear, where the libraries you downloaded will be installed.
  10. Cocoapods configures 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 normally.
  11. It may happen that the Xcode does not recognize the library and emit an error when you first import it. Just give build (Command-B) that this is corrected.
  • Hello Lucas, first of all I appreciate the help, but I think I was not clear, because this part I’ve done...What I need to know is what I call a function that is inside the imported pod. I want to use the functions of the code: https://github.com/richa008/CurrencyTextField

  • within the pod I have the class "class Currencytextfield", so within this class I checked that there is a function: func getCleanNumberString(), I wanted to use this function to sum the values of textfield.

  • 1

    So Luan, I took a look at the class and this function is private, IE, only code written in that same file can access it. You have two options: 1. Edit the library code, make the function public or create a new function; 2. Write your own function, which takes the text from CurrencyTextField and does exactly what function getCleanNumberString() ago.

  • I understood Lucas, I will do as I said and I say what happened, if she was public as I would call inside my Viewcontroller?

  • After initializing (let c = CurrencyTextField()), you can access as c.getCleanNumberString().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.