22

Dependency Management on iOS

Embed Size (px)

Citation preview

Page 1: Dependency Management on iOS
Page 2: Dependency Management on iOS

DEPENDENCY MANAGEMENT

Page 3: Dependency Management on iOS

AGENDA

Introduction to Libraries & Frameworks

Dynamic vs. Static Linking

Manual Dependency Management

Cocoapods / Carthage

Page 4: Dependency Management on iOS

INTRODUCTION TO LIBRARIES & FRAMEWORKS

Page 5: Dependency Management on iOS

LIBRARIES & FRAMEWORKS

Collection of code that allows us to us pre-existing functionality

Libraries: A set of functionality that you can call when needed,

e.g. a matrix multiplication library

Frameworks: The Framework calls your code and provides

you with different extension points, e.g.: UIKit

[1] Martin Fowler on Inversion of Control

Page 6: Dependency Management on iOS

LIBRARIES & FRAMEWORKS ON IOS

Libraries: Statically linked libraries that can only contain code

but no resources

Frameworks: Dynamically linked framework that can contain

code and resource files

Page 7: Dependency Management on iOS

STATIC VS. DYNAMIC LINKING

Page 8: Dependency Management on iOS

STATIC VS. DYNAMIC LINKING

Static Linking: All dependencies are copied into the

executable of the program at compile time

Dynamic Linking: Only references to dependencies are stored

in executable. Dependencies themselves are loaded

dynamically at runtime

Page 9: Dependency Management on iOS

STATIC LINKING

Library 1 Library 2App

Reduces dependencies on the environment in which application will run

Increases app size, can’t share dependencies

Cannot update dependencies after binary has shipped

Page 10: Dependency Management on iOS

DYNAMIC LINKING

Library 1 Library 2

App

Reduces app size, libraries can be shared

Libraries can be updated after binary shipped

More uncertainty about environment in which application will run

Page 11: Dependency Management on iOS

STATIC VS. DYNAMIC ON IOS

System Frameworks (e.g. UIKit) are all linked dynamically, this

way they can be updated without resubmitting an app

Third party dependencies can be linked dynamically and statically since iOS 8, prior only static libraries were allowed

Swift code can currently only be shipped as dynamic

framework, not as static library!

Page 12: Dependency Management on iOS

MANUAL DEPENDENCY MANAGEMENT

Page 13: Dependency Management on iOS

MANUAL DEPENDENCY MANAGEMENT

Download project / add it as a Git submodule

Add project to your existing project

Add framework to project settings

Page 14: Dependency Management on iOS

MANUAL DEPENDENCY MANAGEMENT

Need to maintain dependencies of your dependencies

manually

Non-trivial to update to new versions of your dependencies

Page 15: Dependency Management on iOS

CARTHAGE / COCOAPODS

Page 16: Dependency Management on iOS

CARTHAGE / COCOAPODS

Currently the two most popular dependency managers for iOS

Allow you to define name of dependency and optionally a

version number and will resolve dependencies of your

decencies automatically

Provide simple commands to update to latest version of your

dependencies

Page 17: Dependency Management on iOS

CARTHAGE

Only supports dynamic frameworks, can only be used with

apps that ship to iOS 8.0 or later

Lightweight approach: It downloads your dependencies and

compiles the frameworks, but you still need to add them to

your project manually

Page 18: Dependency Management on iOS

COCOAPODS

Supports both dynamic frameworks and static libraries

Integrated approach: Downloads the dependencies and

restructures your project so that dependencies can be

imported right away

Page 19: Dependency Management on iOS

SUMMARY

Page 20: Dependency Management on iOS

SUMMARYLibraries allow developer to call code, frameworks call your

code and provide customization points for existing

components

Statically linked libraries are compiled as part of the host

application, dynamically linked libraries are loaded at runtime

It’s recommended to use a dependency manager on iOS -

Carthage and Cocoapods are the most popular ones

Page 21: Dependency Management on iOS

ADDITIONAL RESOURCES

Page 22: Dependency Management on iOS

ADDITIONAL RESOURCES

Blog Post: Dynamic Linking

CocoaPods Website

Carthage on GitHub