In the last post, we learned about the introduction part of the Swift Package Manager.
If you missed this, please read Introduction to Swift Package here.
Publishing a Swift Package With XCode
Publish your Swift package privately, or share it globally with other developers. By publishing your Swift packages to private Git repositories, you can manage and integrate internal dependencies across your projects, allowing you to reduce duplicate code and promote maintainability.
Every newly created Swift package comes with a blank Readme.md file for you to modify. Consider adding enough information in the README file so other developers know how to use your Swift package, such as:
- A description of the functionality of your Swift package
- Licensing information
- Supported platforms and versions of Swift — The package version must conform to semantic versioning in order to ensure that your package behaves in a predictable manner once developers update their package dependency to a newer version.
- Contact information
Note — Make sure to commit any changes that you want to include in the release of your Swift package before creating a version tag.
Linking Package Libraries
Your project consists of the source files could be swift, Objective C or other languages and Package which you depend on also source files of various languages and Xcode does collect all source files and compiles package code in a way that its compatible with the app code in your project. So this includes architectures, platforms those things, and then it links it in and combines all of that into the application.
Package libraries are static by default. So that all code links together and this repeated for various apps in your project that use the same package. So if you have the iOS app and WatchOS app it will use the same package.
You can explicitly create a dynamic framework in Swift PM providing the type value in the library like:
When you run the Swift PM, we get the “frameworkname.o” file in derived data when the library type: .static.
Swift Package Manager create the *.framework when library type: .dynamic
Adding Package Dependencies to App
Integrate package dependencies to share code between projects, or leverage code written by other developers.
- Add a Package Dependency
Adding the Swift Package Repository link.
Xcode is verifying the repository.
Resolving the Swift Package Manager dependency from version or branch or commit.
Select the libraries from a package which we import in our applications.
- Edit a Package Dependency
You can’t edit the content of your package dependencies directly. If you want to make changes to a package dependency’s content, you need to check out the Swift package from its Git remote separately. Once you’ve checked out the Swift package locally, drag it into your app’s Xcode project from Finder to add it as a local package.
You can edit it as part of your project; you can fix bugs, or develop new features for the package dependency in tandem with your app.
Note – You can find the Package.resolved file inside your .xcodeproj directory at [appName].xcodeproj/project.workspace/xcshareddata/swiftpm/Package.resolved.
Updating Swift Package
Delete a Package Dependency
Network Manager Framework link — https://github.com/yo2bh/NetworkManager