Home > CocoaPods, iOS > CocoaPods, locally speaking

CocoaPods, locally speaking

2. February 2013 Leave a comment Go to comments

CocoaPods is a simple-to-use but efficient framework for managing dependencies in Xcode. You might have already used it to manage library dependencies hosted on GitHub. Otherwise, take a look at the CocoaPods website first. But do you also know that you can use CocoaPods to manage dependencies that are not stored in a GitHub repository or any other remote repository at all? Let’s see how to do that.

Let’s say, you have an Xcode project named Provider which you want to include into another Xcode project named Consumer. First, you need to write a pod specification for your Provider project. The crucial part of specifying a local dependency is how you define the source attribute. In this case, source should contain a path to the Provider repository, relative to the Podspec file. So, if you placed the Podspec into the root of the Provider project, the path will be '.'. The second option of the source attribute needs to be a tag or a commit number. If you want to test your changes while developing, you will probably use a commit number, for example: 'abcd123'. Putting both things together, we get:

s.source = { :git => '.', :commit => 'abcd123' }

The remaining part of the Podspec won’t differ from the one you would write to use with a remote repository. So, your Podspec will look something like this:

Pod::Spec.new do |s|
    s.name = 'Provider'
    s.version = "0.0.1"
    s.summary = 'Provider is a framework for consuming RESTful web resources on iOS.'
    s.homepage = 'https://bitbucket.org/<some-username>/provider'
    s.license = 'Apache License, Version 2.0'
    s.author = { 'Natalia Ossipova' => 'natalia.ossipova@<some-domain-name>.com' }
    s.source = { :git => '.', :commit => 'abcd123' }
    s.platform = :ios, '5.0'
    s.requires_arc = true
    s.source_files = 'Provider'
    s.resources = 'Provider/Default.png', 'Provider/Default@2x.png', 'Provider/Default-568h@2x.png', 'Provider/en.lproj/InfoPlist.strings'
end

To find out what other attributes you might need to fill in refer to the CocoaPods wiki.

Here are some tips to make you Podspec work:

    • If your Xcode project contains subfolders, list all of them containing source files in the attribute source_files:
  • s.source_files = 'Provider', 'Provider/Globals', 'Provider/Model', 'Provider/View', 'Provider/Services'</code>
    
    • If you defined imports globally in a *.pch file, specify it as the prefix_header_file attribute:
  • s.prefix_header_file = 'Provider/Provider-Prefix.pch'
    
    • List all resources, i.e. all PNG, *.strings and XIB files, in the resources attribute.
    • Give your Localizable.strings file of the Provider project a unique name, e.g. Provider-Localizable.strings, and use NSLocalizedStringFromTable in the Provider code.
  • After finishing and validating the Provider Podspec, you need to point your Consumer to Provider by using the :path option in the Podfile of Consumer. The path to the Provider project can be relative to the Podfile. If, for instance, you checked out both projects into the same folder, your Podfile will look like this:

    platform :ios, '5.0'
    pod 'Provider', :path => '../Provider'
    

    Now, you can install the Consumer dependency and work on both projects. Don’t forget to update the commit number in the Podspec each time you’ve committed your changes on Provider to a local repository.

    Advertisements
    1. 23. May 2013 at 16:49

      Thanks, exactly what I needed today. Seems like the option :local of a pod has been deprecated and is called :path, though.

    2. 23. May 2013 at 20:11

      Thank you, Heiko. I knew about deprecation of :local https://twitter.com/nossipova/status/331700157559238657 and just waited for CocoaPods docs to be updated. Nevertheless, I’ve amended my post accordingly.

    3. horseshoe7
      19. November 2013 at 13:27

      Hi Natalia! Great post. My question is now that I use this local pod in another project, in that other project, this local pod appears under “Development Pods” and not “Pods”. OK… but the question is: Is it normal that none of my source appears here or have I configured something incorrectly? The source files seem to be located correctly in the podspec, because when I run lint on this podspec they are found and analyzed.

    1. No trackbacks yet.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s