Using and Creating Cocoapods

Using and Creating Cocoapods

There was a great turnout for my talk about Cocoapods tonight at iOSKW. I think it went fairly well although I felt I rushed through it a little bit. The slides and demo notes are included below for those who attended. When I get a few moments I’m going to record a short screencast so it’s more useful to non-attendees as well.

View on Slideshare here

Download the slides as PDF as well as the demo source code.

Here’s the notes for the “Demo” portion of the talk:

Using Cocoapods Demo

  1. Create a new Single View project in Xcode called MyProject.
  2. Create Podfile in project root.
  3. Search Cocoapods.org for a pod (AFNetworking).
  4. Point out features of web site.
  5. Use clipboard icon to copy/paste AFNetworking.
  6. Run pod in terminal (installation).
  7. Point out errors/warnings.
  8. Point out and explain loc file (bbedit Podfile.lock).
  9. Point out installed dependencies (if any).
  10. Point out Pods.xcconfig.
  11. Change the pod file (Remove AFNetworking and add SVProgressHud).
  12. Run pod again to see removal and updates.
  13. Open MyProject.xcworkspace
  14. Add a SVProgressHud call on ViewDidAppear of primary view controller.

    - (void)viewDidAppear:(BOOL)animated {
            [SVProgressHUD showSuccessWithStatus:@"It Worked!"];
    }
    
  15. Build and run the app.

Creating Podspec Demo

  1. Open and demonstrate AwesomeProject.
  2. Decide to create a pod for UIViewController+Alerts category.
  3. Show pod creation help in terminal: pod lib (note options).
  4. Create a library on the ~/Desktop pod lib create iOSKW.
  5. Explain the folder structure.
  6. Copy in UIViewController+Alerts.h & .m files into Classes/ios.
  7. run pod lib lint.
  8. note warnings and errors.
  9. Edit bbedit iOSKW.podspec as follows:

    Pod::Spec.new do |s|
     s.name         = "iOSKW"
     s.version      = "0.1.0"
      s.summary      = "UIViewController Categories."
      s.homepage     = "http://example.com"
      s.license      = 'MIT'
      s.author       = { "jsambells" => "jeffrey@speakfeel.ca" }
      s.source       = { :git => ".", :tag => s.version.to_s }
      s.platform     = :ios, '7.0'
      s.requires_arc = true
      s.source_files = 'Classes/ios/*.{h,m}'
     s.frameworks   = 'UIKit'
    end
    
  10. Run pod lib lint.
  11. Commit to local git repo.
  12. Tag local git as 0.1.0 to match Podspec.
  13. Re-run pod lib lint to verify
  14. Create demo app called Demo on desktop and copy contents to the lib folder.
  15. Remove empty targets from default Podfile (will error if you don’t!).
  16. Run pod in Project, note output.
  17. Import <iOSKW/UIViewController+Alerts.h> header into primary view controller.
  18. And add test code to view did load.

    - (void)viewDidLoad
    {
      [super viewDidLoad];
      [self alert:@"Hello!"];
    }
    
  19. Run demo app.