Published on

Swift Packages 101

Authors

Swift Packages 101

A note about package creation in Swift & Xcode.

Create

  1. File -> New -> Swift Package
  2. Create package for current project and current target.
  3. Drag package's files to Sources/PackageName folder.
  4. Move whole package's folder to desktop with Option key pressed to create a copy.
  5. Open Package.swift: now it is a separate project which can be put under version control and used in other projects.

Upload to Github

Swift Package could be uploaded as either public or private repo. Versioning is important, the common is: major.minor.patch

Use

The following steps assume the Package is uploaded to Github.

  1. File -> Swift Packages -> Add Package Dependency
  2. Copy link to package. For private package copy SSH link.
  3. Connect and enjoy.

Edit

In order to switch between local/remote packages drag desktop's version of package back to project, and Xcode should automatically switch from remote package version to local one.

When local changes were done, go back to remote by deleting local version of package from the project.

Conclusion

In comparison to Cocoapods, Swift Packages are much easier to create, use and edit.