Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have a Swift Package and I want to know how to get the current version of this package

Similar to how you get your apps version kCFBundleVersionKey how does one get the version of the package you are working in?

like image 350
Malcolmn Roberts Avatar asked May 25 '20 11:05

Malcolmn Roberts


3 Answers

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)

like image 61
Luca D'Alberti Avatar answered Sep 19 '22 17:09

Luca D'Alberti


You can check package version rules in project package dependencies tab. Check screenshot below. Propably it would be sufficient for most use cases. enter image description here

like image 35
Mr.SwiftOak Avatar answered Sep 19 '22 17:09

Mr.SwiftOak


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.

This is how

like image 38
Frankenstein Avatar answered Sep 21 '22 17:09

Frankenstein