Similar to how you get your apps version kCFBundleVersionKey
how does one get the version of the package you are working in?
I don't think it's possible at the moment to get the value easily.
You can either read the Package.resolved
file or you can set up a public constant where you would define the version of your library.
public let version = "0.0.1"
import MyLibrary
print(MyLibrary.version)
There isn't a standard way how to do this, every package could have a different constant (or not have it at all)
You can check package version rules in project package dependencies tab. Check screenshot below. Propably it would be sufficient for most use cases.
Edit: The context has changed, the question was to get the version of MyPackage
I'm working on via code. There isn't any documented or recommended method as of now. Though this can be achieved by a hack through reading the Package.resolved
file as mentioned by Malcolm.
I'm not deleting this answer for any future users who are looking for answer on how to get the exact latest version of a Package.
You can give the same major version number and give Update to latest package version
option on Xcode. eg: If current version is 2.4.5 you just need to provide 2.0.0 and update. There is also an option to provide the exact version of swift package you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With