- Published on
Swift Packages 101
- Authors
- Name
- Maria Saveleva
- @lyumotech
Swift Packages 101
A note about package creation in Swift & Xcode.
Create
File -> New -> Swift Package
- Create package for current project and current target.
- Drag package's files to Sources/PackageName folder.
- Move whole package's folder to desktop with Option key pressed to create a copy.
- 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.
File -> Swift Packages -> Add Package Dependency
- Copy link to package. For private package copy SSH link.
- 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.