Dependency Management mittels CocoaPods - inovex.de · Das Tool: CocoaPods • Dependency Manager...

33
Oliver Bayer | inovex GmbH Dependency Management mittels CocoaPods

Transcript of Dependency Management mittels CocoaPods - inovex.de · Das Tool: CocoaPods • Dependency Manager...

Oliver Bayer | inovex GmbH

Dependency Management mittels CocoaPods

In den nächsten 45min• 10.000 BC: Die Zeit vor CocoaPods

• Das Tool: CocoaPods

• Eigene Podfile zur Definition von Abhängigkeiten

• Lokale / Private Pods

• Misc

���2

10.000 BC*

• Aufkommen von 3rd Party Bibliotheken

• Woher?

• Wohin?

• Transitive Abhängigkeiten

• Aktualisieren / Entfernen von Bibliotheken

���3*Before CocoaPods

Das Tool: CocoaPods

• Dependency Manager für Objective-C

• Open Source

• In Ruby geschrieben

• Convention over Configuration

���4

CocoaPods Installieren

sudo gem install cocoapods

���5

init

install*

lib

repo

search

setup

spec

pod

*default ���6

pod setup

• Einmalig zum Initialisieren

• Erstellt ~/.cocoapods

• Lädt aktuelles Podspec Repo von Github

���7

Podfile

• Heißt einfach nur: Podfile

• Liegt im selben Verzeichnis wie .xcodeproj

• Enthält Angaben zur Plattform

• Definiert die Abhängigkeiten (Pods)

���8

Minimale Podfile

platform :ios, ‘7.1’

���9

pod search

$pod search AFNetworking

-> AFNetworking (2.2.1)

A delightful iOS and OS X networking framework.

pod 'AFNetworking', '~> 2.2.1'

���10

Deklaration eines Pods!

pod ‘AFNetworking’, ‘2.2.1’ !

• Versionsangabe ist optional

• Versionsbereiche: >, =>, <, <=, ~>

• Bleeding Edge :head

���11

Podfile Zwischenstand

platform :ios, 7.1

pod ‘AFNetworking’, ‘2.2.1’

���12

pod install

• Vorbedingung: Podfile

• Erstellt beim ersten Aufruf ein .xcworkspace

• Erstellt Podfile.lock Datei

• Erstellt Pods Verzeichnis

���13

Projekt und Target• Default: XCode Projekt im selben

Verzeichnis wie Podfile

• xcodeproj ‘MTC2014’

!

• Default: Erstes Target im Projekt

• link_with ‘MTC2014’, ’MTC2014Tests’

���15

Podfile Zwischenstandplatform :ios, 7.1

!

xcodeproj ‘MTC2014’

link_with ‘MTC2014’, ‘MTC2014Tests’

!

pod ‘AFNetworking’, ‘2.2.1’

���16

���17

Abhängigkeiten pro Target

target :MTC2014Tests do

pod 'Kiwi'

end

���18

���19

Lokale Pods

• Bug / Erweiterung in einem Pod

• Änderung an Pods Dateien werden durch pod install / update überschrieben

• Lokale Pod benötigt .podspec

���20

Lokale Pods

pod ‘AFNetworking’, :path => ‘~/AFNetworking’

!

• Podspec Datei aus ~/.cocoapods

• Pfad Angabe absolut oder relativ zur Podfile

���21

Lokale Pods

pod ‘INOAuth’, :path => ‘libs/INOAuth’

!

• Per Git Submodule ins Projekt

• Versionierung

• Won’t happen!

���22

Private Pods

pod ‘INOAuth’, :git => ‘https://inovex.de/INOAuth.git’

!

• Abholen des Pods erledigt CocoaPods

• git, hg, bzr, svn, http

• :tag => ‘0.1’

���23

Private Pods

pod ‘INOAuth’, :git => ‘https://inovex.de/INOAuth.git’

!

• Skaliert nicht

• .podspec Datei

���24

Privater Repo Server

!

!

• pod repo add REPO_NAME SERVER_URI

• Git Repo

• pod ‘INOAuth’, ‘0.1’

���25

Podspec

• Beschreibt ein Pod

• Allgemeine Infos (Autor, Beschreibung)

• URI der Sourcen

• Build Einstellungen

• Weitere Abhängigkeiten

���26

PodspecPod::Spec.new do |spec|

spec.name = ‘INOAuth'

spec.version = ‘0.1’

spec.authors = 'Oliver Bayer' => ‘[email protected]

spec.summary = ‘Simple Authentication Provider for iOS'

spec.source = :git => ‘https://inovex.de/INOAuth.git', :tag => ‘0.1'

spec.source_files = ‘INOAuth.{h,m}’

spec.requires_arc = true

end

���27

Pre-/Post-Install Hooks

• Werden bei install ausgeführt

• Pre-Install: Pod

• Post-Install: Projekteinstellungen

• Global

���28

Post-Install Hook

post_install do |installer|

installer.project.targets.each do |target|

target.build_configurations.each do |configuration|

configuration.build_settings['ARCHS'] = '$(ARCHS_STANDARD_32_BIT)'

end

end

end

���29

Wenn gar nichts mehr geht

rm -rf Pods

rm Podfile.lock

rm *.xcworkspace

pod install

���30

Vor-/Nachteile• Deutlich vereinfachtes

Dependency Management

• Vereinfacht Erstellen von Libs (Modularisierung)

• Weg zurück wird nicht verbaut

!

• Software == Bugs

• Benötigt auch ein wenig Einarbeitungszeit

���31

Misc• Q: Was gehört in die Versionsverwaltung?

A: Podfile, .xcworkspace, Podfile.lock

• Q: Und die Pods?

A: Kommt drauf an

• Q: Wird das binary durch die libs nicht unnötig gross?

A: Der Linker nimmt nur das was er braucht

���32

Vielen Dank für Ihre Aufmerksamkeit

Oliver Bayer Mobile Development !inovex GmbH [email protected] !@oliverbayer