How to change the version of library in Swift Package Manager? - ios

I used some libraries in my swiftUI project with help of Swift Package Manager.
But I want to use some previous version of one library.
What I am tried:
If I change here it nothing reflects.
Can anyone suggest how to change the version of particular library?

You can use an exact version of the package that you want.
Just select the drop down beside Up to next major and choose Exact.
Then insert the exact version that you wish to use.

Related

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?
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.

Adding support for SwiftPM to Swift Library

Last one hour or so I have been looking at how to add SwiftPM support to the open-source library.
I started mimicking Alamofire's Package.swift file.
// swift-tools-version:5.1
import PackageDescription
let package = Package(name: "MASegmentedControl",
platforms: [.iOS(.v10)],
products: [.library(name: "MASegmentedControl",
targets: ["MASegmentedControl"])],
targets: [.target(name: "MASegmentedControl",
path: "MASegmentedControl")],
swiftLanguageVersions: [.v4, .v4_2, .v5])
But when I am trying to add that to a test project as swift package I am getting error as shown below.
When I run swift package tools-version I get the output as 3.1.0. I am running Xcode 11.2.1.
I also tried looking at how to update swift package tool. I couldn't find anything on it.
I am wondering if anyone of you added SwiftPM support to your libraries, can please help me out. I am missing something but I can't put my finger on it.
Any help or pointers would be greatly appreciated.
Thanks a lot for reading my post.
I think that can be appeared due to one of the following:
1- Regarding the documentation, May you need to remove the "swiftLanguageVersions" key.
https://swift.org/blog/swift-package-manager-manifest-api-redesign/
The tools version also determines the default Swift language version
used to compile the package’s sources. Existing Swift 3 packages will
compile in Swift 3 compatibility mode. You can optionally use the
swiftLanguageVersions property in both Swift 3 and Swift 4 manifests
to set the language version used to compile that package, if you don’t
want the default version. This means it is possible to upgrade a
package to use the newer manifest format without upgrading its sources
to Swift 4.
2- Ensure the following format for the commented line, as follows:
// swift-tools-version:5.1
import PackageDescription
// swift-tools-version:. Packages that omit this special
comment will default to tools version 3.1.0.

Convert to Current Swift Syntax Failed - "No such module" (Swift 4, Xcode 9)

In Xcode 9, I am trying to do the automatic conversion to Swift 4.
It fails with the following message:
Convert to Current Swift Syntax Failed
Please ensure that all selected targets build successfully with the currently configured Swift version before attempting a migration.
It's complaining of a missing module. But when I do a regular build there are no issues. Not sure if this is relevant, but the module (which Xcode is complaining is missing) was already converted to Swift 4 earlier (in it's own project).
Note: No Cocoapods / Carthage used here.
Note: Two solutions tried (and worked) but do not address the underlying issue.
One solution is to do the conversion manually (change Swift version to 4 in build setting and apply Fix-Its one by one until no more build errors).
Another solution is to disable the third party framework (comment out all code where it's used), do the auto-migration, and then re-enable the framework. This could get pretty difficult with bigger projects.
I can't find any solution yet.
For now I fix manually setting Swift Language Version
After changing from 3.2 to 4.0 I compile and fix errors and warnings manually.
I'm waiting for a better solution!
I also got this problem while converting my project to Swift 4.0. Looks like problem appears when you try to convert target which imports a framework which is already in Swift 4.0. At your screenshot you try to convert 'RecipeTextParser' which imports 'SovaTools' which is already Swift 4.0.
I found dirty, but working solution. You can use older(Swift 3.2) version of 'SovaTools' when converting. You should NOT check it's mark in target selection window of conversion tool. Then, when 'RecipeTextParser' will be successfully converted you can use Swift 4.0 'SovaTools' version again.
I got this error and in my case one of my Pods(the one Xcode was complaining about) was a Swift 4 target and the rest were Swift 3.2. Looking at the build logs it looks like Xcode built that framework in one location and was searching for it in another. When I reverted that Pod to an older version(that used Swift3.2) the problem went away. Obviously a Xcode bug. HTH
Just update your pod and it will resolve the issue.
To update pod:
open terminal and go to your project directory
type pod update
This resolved my issue.
Xcode (Xcode 9) language migration feature is not as much accurate that it can migrate your complete code/project from one swift version to another with zero tolerance. It skips few code migration for us (developers). It may be bug or inaccuracy of tool. But you need to put some manual effort also, to completely migrate swift language version for your project/code.
Now, according to your snapshot, Xcode is showing and error for 'RecipeTextParser' framework. I think this is an external/third party framework. Another point to note, you've integrated this framework using CocoaPods:
Any one of following can be reason for failure of code migration:
CocoaPods locks framework (files) for editing. So language migration process may not be able to migrate (or identify) code for external/thirdparty framework.
In general terms, Framework is package of code files, so framework itself may not allow file/source code editing.
Suggestion as solution:
Update your cocoa pods as well as all frameworks integrated using cocoa pods compatible to latest swift language version.
If you've manually integrated/added external/third party frameworks, then you need to update/replace those also.
Some manual effort is required to completely migrate code between swift languages. I tried swift migration with above options and my all projects are now compatible with swift 4.

adding libz.1.2.3.dylib vs libz.1.1.3.dylib or libz.1.2.5.dylib

I am following this tutorial
The tutorial states to add libz.1.2.3.dylib. library, but because I have downloaded newer or older library (I don't know exactly if my library is newer or older that the library in the tutorial, but 99% it is newer). So, when I tried to add the libz.1.2.3.dylib. library, I didn't find it. However, when I typed libz I found these choices:
which one should I choose please?
In using dynamic libraries the one you normally use is libX.major_version.dylib in this case libz.1.2.dylib. This is a link to a library libX.major_version.minor_version.dylib which here is libz.1.2.5.dylib
The rationale for this is that the major version is changed only when the API is changed, the minor version is updated when any change is made. Thus your program should work when it uses any of the same major version and so you want the latest version.
In this case the tutorial had an older install and so its libz.1.2.dylib. should have pointed to libz.1.2.3.dylib.
For you you should use libz.1.2.5.dylib which should be like the tutorials version but with bug fixes and possibly extra functions that don't matter here as the tutorial won't call the new functions.
Normally libX.1.x.dylib would be older than libX.2.y.dylib but the writers might produce bug fixes to the old API whilst also working on the new API
Following on from the rational I gave libz.dylib should be a link to the highest number library but I would not use it as you are writing to a particular API so I would use a version specific (In this case if missing a link the I would not trust what libz.dylib points to)

How to give a static library a version number?

We have a static library in Xcode which we need to assign a version number to, just like in an app.
This is useful for many reasons, but mainly because if we could assign a version number we could easily build the library to a specific output folder:
Library-1.0.0
Library-1.0.1
Library-1.0.2
Library-1.1.0
Library-2.0.0
If you see what I mean.
It might also be useful for our clients to manage dependencies and such in their apps.
Is there a way that we can add a version number to the build?
Thanks for your help.
This has everything you need to know: Framework Versioning
Essentially it boils down to a few settings within the framework's Build Settings. There are Major versions and Minor versions. Major version is found in the build setting "Framework Version". It starts off with a value of "A" by default. Minor versions are set with the setting "Current Library Version".
Major versions indicate incompatiblity with previous frameworks. Minor versions indicate compatible updates to the current version.

Resources