Top Banner
34

Cocoa pods iOSDevUK 14 talk: managing your libraries

Jun 25, 2015

Download

Technology

Diego Freniche

How to manage and organize your project using Cocoa pods, Synx, private pods, etc.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Cocoa pods iOSDevUK 14 talk: managing your libraries
Page 2: Cocoa pods iOSDevUK 14 talk: managing your libraries

Bore%Da!• Diego'Freniche

• @dfreniche

• I'develop'Apps

• also'teach'people'how'to'do'it

• iOS/Android/BB10/webOS/...

Ultra&geek*CV:*h/ps://github.com/dfreniche/cv

Page 3: Cocoa pods iOSDevUK 14 talk: managing your libraries

Warning!• This&talk&is&maybe&Dave&Addey&approved

• I'm&going&to&talk&about&lots&of&third&party&libraries,&specially&for&networking&code,&so&for$sure$is$not$Markus$Zarra$approved!

Page 4: Cocoa pods iOSDevUK 14 talk: managing your libraries

The$tradi*onal*$approach$to$library$managementlike%in%"tradi,onal"%==%bad

Page 5: Cocoa pods iOSDevUK 14 talk: managing your libraries

• write'your'code

• find'some'libraries'on'StackOverflow

• download'them'from'github

• unzip'&'add'to'your'project

• which%folder%do%I%have%to%add%to%my%project?

• try'to'keep'that'mess'organized

• ...'good'luck'with'that'

Page 6: Cocoa pods iOSDevUK 14 talk: managing your libraries

What%if...?• there's(a(new(version(of(your(libs(with(more(features?

• there's(a(fixed(bug(you(don't(know(about?

• GOTO$Tradi)onal$approach

Page 7: Cocoa pods iOSDevUK 14 talk: managing your libraries

Cocoa%Pods%light%introduc1on• Abstract

• The,idea

• The,Philosophy,behind,Cocoa,Pods

• Something,very,clever,here

• Are,you,s;ll,awake?

• Kill,by,PowerPoint

Slide&1&/&300

Page 8: Cocoa pods iOSDevUK 14 talk: managing your libraries
Page 9: Cocoa pods iOSDevUK 14 talk: managing your libraries

Talk%is%cheap.%Show%me%the%code.• Linus'Torvalds

Page 10: Cocoa pods iOSDevUK 14 talk: managing your libraries

Install'Cocoa'Pods

The$easy$way:

$ sudo gem install cocoapods

Update'Cocoa'Pods

GOTO EASY_WAY

Page 11: Cocoa pods iOSDevUK 14 talk: managing your libraries

A"pod"file

platform :ios, '7.0'

pod "AFNetworking", "~> 2.0"

pod "ARAnalytics", "~> 2.7"

Page 12: Cocoa pods iOSDevUK 14 talk: managing your libraries

Create&pod&file

$ pod init

Page 13: Cocoa pods iOSDevUK 14 talk: managing your libraries

Using&more&than&one&target?

platform :ios, "6.0"

target "SuperHeroes" do

end

target "SuperHeroesTests" do

end

Page 14: Cocoa pods iOSDevUK 14 talk: managing your libraries

Final&pod&fileplatform :ios, "6.0"

target "SuperHeroes" do

pod 'AFNetworking', '~> 2.2'pod "NSLogger"

end

target "SuperHeroesTests" do

end

Page 15: Cocoa pods iOSDevUK 14 talk: managing your libraries

Install'podspod install

Analyzing dependenciesDownloading dependenciesInstalling AFNetworking (2.3.1)Installing NSLogger (1.2)Generating Pods projectIntegrating client project

[!] From now on use `SuperHeroes.xcworkspace`.

Page 16: Cocoa pods iOSDevUK 14 talk: managing your libraries

[!]$From$now$on$use$SuperHeroes.xcworkspace.

Page 17: Cocoa pods iOSDevUK 14 talk: managing your libraries

[!]$From$now$on$use$SuperHeroes.xcworkspace.

Page 18: Cocoa pods iOSDevUK 14 talk: managing your libraries

Duplicated+code!

Delete%duplicated%code...%Sweet!

Page 19: Cocoa pods iOSDevUK 14 talk: managing your libraries

Change'imports

#import "NSLogger.h"

becomes:

#import <NSLogger.h>

Page 20: Cocoa pods iOSDevUK 14 talk: managing your libraries

It#compiles#and#runBut$doesn't$run$tests

Page 21: Cocoa pods iOSDevUK 14 talk: managing your libraries

link_with 'MainTarget', 'MainTargetTests'Move pods to common area 'MainTarget'

$ pod install

Because'StackOverflow

Page 22: Cocoa pods iOSDevUK 14 talk: managing your libraries

Edit%Podfile%within%Xcode• even%install%Pods%using%Alcatraz%+%Cocoa%Pods%plugin

• Run%pod install%from%Xcode!

Page 23: Cocoa pods iOSDevUK 14 talk: managing your libraries

Use$Groups,$please!• But%groups%alone%doesn't%suffice

• No%Finder%organiza7on

Page 24: Cocoa pods iOSDevUK 14 talk: managing your libraries

Enter&Synx!• h#ps://github.com/venmo/synx

• Install9it:

$ sudo gem install synx

• Use%it

$ synx SuperHeroes.xcodeproj/

Page 25: Cocoa pods iOSDevUK 14 talk: managing your libraries

Our$own$libraries$as$Pods

Page 26: Cocoa pods iOSDevUK 14 talk: managing your libraries

You$need$two$things• Your&library&repo

• A&PodSpec,&inside&a&repo

Add#that#PodSpec#to#the#Cocoapods#specs

Page 27: Cocoa pods iOSDevUK 14 talk: managing your libraries

git initgit add README.mdgit commit -m "Initial commit"git remote add origin https://github.com/dfreniche/Private-CocoaPods.gitgit push -u origin master

cd MarvelAPIHelper/0.0.1/

Page 28: Cocoa pods iOSDevUK 14 talk: managing your libraries

Create&the&Spec

pod$spec$create$PrivateLibrary

Check&the&spec

pod$spec$lint$PrivateLibrary.podspec

Page 29: Cocoa pods iOSDevUK 14 talk: managing your libraries

Add#repo#to#CocoaPods#list

pod$repo$add$MarvelAPIHelper$h0ps://github.com/dfreniche/Private>CocoaPods.git

Update'the'spec

pod$repo$update$MarvelAPIHelper

How$to$remove$a$Private$Repo

pod$repo$remove$[name]

Page 30: Cocoa pods iOSDevUK 14 talk: managing your libraries

Check&our&newly&installed&spec!

cd ~/.cocoapods/reposcd MarvelAPIHelper/pod repo lint .

Page 31: Cocoa pods iOSDevUK 14 talk: managing your libraries

Success!/usr/bin/pod install

Analyzing dependenciesDownloading dependenciesUsing AFNetworking (2.3.1)--> Installing MarvelAPIHelper (0.0.1)Using NSLogger (1.2)Using OCHamcrest (4.0.1)Using OCMockito (1.3.0)Using TPWeakProxy (1.0.0)Generating Pods projectIntegrating client project

Page 32: Cocoa pods iOSDevUK 14 talk: managing your libraries

Review• CocoaPods:*best*tool*for

• 3rd*party*library*management

• conflict*/*dependencies*resolu;on

• stay*updated

• managing*your*own*libraries

Page 33: Cocoa pods iOSDevUK 14 talk: managing your libraries

Thanks!Everything+was+crystal+clear,+so+no+ques5ons+

needed

Contact'/'send'beer:'@dfreniche

Page 34: Cocoa pods iOSDevUK 14 talk: managing your libraries

Links• h#p://cocoapods.org

• Private4pod4spec4repo:4h#ps://github.com/dfreniche/Private:CocoaPods

• Example4App4using4Pods4and4the4private4Pod:4h#ps://github.com/dfreniche/MarvelAPIHelper