Cheatsheet Swift - Distribute and Use Library

May 20, 2019
swift cheatsheet

Distribute and use library

This cheat sheet for Swift 5 contains ways of creating a distributable and using distributable created by others.

Create a distributable module

Swift Package Manager

swift package init

CocoaPods

pod lib create LIBRARY

Use modules created by others

Swift Package Manager

Add/Update dependency
import PackageDescription

let package = Package(
  name: "<PROJECT>",
  dependencies: [
    .package(url: "https://github.com/<USER>/<REPOSITORY>.git", from: "<TAG>")
  ],
  targets: [
    .target(name: "<TARGET>", dependencies: [<DEPENDENCY_ONE>, <DEPENDENCY_TWO>])
  ]
)
Sync after Add/Update
swift build

CocoaPods

Add/Update dependency
# Podfile
use_frameworks!

target '<TARGET>' do
    pod '<DEPENDENCY_ONE>', '~> <TAG>'
    pod '<DEPENDENCY_TWO>', '~> <TAG>'
end

target '<TEST_TARGET>' do
    pod '<TEST_DEPENDENCY_ONE>', '~> <TAG>'
    pod '<TEST_DEPENDENCY_TWO>', '~> <TAG>'
end
Sync after Add/Update
pod install
comments powered by Disqus