How to Install Package in Xcode via Swift Package Manager - swift

I'm working on a project in Xcode and am attempting to install and use the CryptoSwift package via the Swift Package Manager.
I read the documentation on SPM, but I don't see instructions on how to invoke the SPM through Xcode.
The examples often refer to calling $ swift build. Does this mean that the SPM is only accessible from the command line?
And if so, where exactly am I supposed to create the Package.swift file?
I'm reasonably familiar with Xcode, but I don't really understand the meaning of the build settings part of a project, or how Swift modules are used.
EDIT: This question was originally asked for Xcode 7.2, which shipped with Swift 2.1.1. Will gladly accept answers that explain how to do this with current/future versions of Xcode.

Swift Package Manager now support generating Xcode project with
swift package generate-xcodeproj
as mentioned in this answer, but this only works when developing a library, or a command line tool. Not (yet) for (iOS/OS X) graphical application developer:
Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.
Note:
It might not work well if there is a space in your package name, i.e. change "App Store" to "AppStore".

At present, to use the Swift Package Manager aka SPM, you need to install the development version of Swift 2.2 provided by Apple here. Xcode 7.2 shipped with Swift 2.1.1 and does not work with the SPM unless Swift 2.2-dev is installed.
You can compile with Swift 2.2-dev but you will need to do the build of CryptoSwift on the command line using swift build. When the library and modulemaps are built, you can drag and drop them into Xcode 7.2 using the Finder. SPM puts the required files into a .build directory. But Xcode 7.2 needs to be started with the alternate toolchain. This can be done from the command-line using xcrun launch-with-toolchain /Library/Developer/Toolchains/swift-latest.xctoolchain You should be able to import from the modules/libraries built with the SPM.
Note though, that you cannot submit iOS apps to the Store at the moment that have been built with the 2.2 development version. You can build/run/test things generally without problem, although Playgrounds are not functional and there can be Xcode issues with the debugger.

June 4th, 2019 update. Swift 5 and SPM 5 has added this support and Xcode 11 integrates with SPM.

Related

ARKit+Xcode:Module compiled with Swift 5.0.1 cannot be imported by the Swift 5.3.2 compiler:

I am trying to build an AR app with ARKit, trying to run these open-source ARKit project and Plugins on github:
https://github.com/augmentedrealityplugin/shapeDetection
https://github.com/ShawnMa16/AR-Drawing
However I have this problem
I have tried the solutions:
Set 'Yes' in Build Libraries for Distribution
installing the Xcode Toolchain
delete and add the framework again in Embedded Frameworks
But it cannot help, is there any solutions to my problem, so I can at least try and run these project and Plugins on GitHub?
Swift obtained ABI compatibility in v5.0. But only gained module compatibility in v5.1. So, frameworks compiled with a version before 5.1 are toolchain specific. This is what what the compatibility error you’re receiving refers to.
Pre 5.1, you need to compile both your application and the library with the same version of the Swift compiler. With 5.1 and beyond, preferably, use the latest toolchain for both, but that is optional as long as they are at least compiled with 5.1 or greater. Existing binary distributions of the library compiled pre v5.1 will not work with the latest version of Xcode.
This means you’ll need to compile the library from source, upgrading the Xcode project settings to at least 5.1, and possibly the source code, as necessary.
See this post for more details: https://swift.org/blog/abi-stability-and-more/

Swift command-line app that uses ArgumentParser

I have a command line app written in Swift. It does not use the Swift package manager, and instead has a rather complex xcode project.
I want to use ArgumentParser. The documented way to do this is to import the Swift package, which Xcode 11 can do in the GUI.
The problem is that the built executable depends on the ArgumentParser framework's dylib. I need a standalone executable that doesn't depend on dynamic libraries besides those that come with Catalina.
When I use the Swift package manager to build a project that depends on ArgumentParser, it is able to do so without a dynamic library dependency. It seems to link in the swiftmodule file.
Is it possible to build a command line app using Xcode that uses ArgumentParser without requiring me to distribute the ArgumentParser dylib along with my main app binary?

Module compiled with swift X.1 cannot be imported in Swift X.0.2

Swift 3.1 came out and I'm receiving this error message in my project:
Module compiled with swift 3.1 cannot be imported in Swift 3.0.2
So how do I tell Xcode to start updating my project and migrate it to Swift 3.1?
It is likely that you are including 3rd party frameworks/libraries. Those are what need to be updated/recompiled. If you are using Carthage or Pods you should just rebuild those libraries and make them available to your app. The problem isn't your code. When you compile it, it will compile to 3.1
etayluz
Upgrade your Xcode to 8.3 and your Swift version will be 3.1
I use Carthage to update library/framework again, with option --no-use-binaries
carthage update --no-use-binaries
These steps helped me.
These things happens sometimes when your Xcode doesn't support certain version of your third party dependencies.
Try to use proper version of your third party dependencies compatible with Xcode version.
Clear your Derived data in Xcode. Xcode -> File -> Workspace settings -> Click on the grey arrow mark beside Derived data.
Check carthage version by running carthage version. It should be above 0.20.0. Run carthage update --platform iOS --no-use-binaries in your terminal. Gets rid of compatibility issues.
Clean your project. Command + Shift + K. Then build and run.

Why is Swift build command only available in development?

I'm learning Swift now, and I found out that the swift build command is available only in the development version of Swift.
So when I invoke
swift build
...it returns:
swift build unable to invoke subcommand.
Can someone explain why?
In another answer I found the above command, but why is it only available in the development version?
Swift Package Manager is included with Swift 3.0 and above. You should be able to use it now with the released versions that are included with Xcode 8 or downloadable on swift.org.

Downgrade xcode project from swift 3 to swift 2.2

I downloaded the new xCode 8 beta. When i opened my old project(in swift 2.2), i clicked the convert to new swift syntax, and i clicked swift 3. The problem is that i use a framework downloaded with carthage (Kanna). I have tried to use the:
carthage update
but it doesn't work.
When i try to run the code on the new Xcode-beta, i get this error:
Module file was created by an older version of the compiler; rebuild 'Kanna' and try again:
Seems like i am very late to answer but there is update available for 'Kanna' framework supporting swift 3.0. You can add this to your podfile if you use CocoaPods
use_frameworks!
pod 'Kanna', '~> 2.0.0'
Or for Carthage you can install like
github "tid-kijyun/Kanna" ~> 2.0.0
First of all save a backup of your current project. Now!
Solution 1
Open your project with Xcode 7.3.1, it uses Swift 2.2 so it will signal you a bunch of errors. Since you know Swift 2.2 you should be able to fix the errors and make you project again compatible with Swift 2.2
Solution 2
In Xcode 8 beta you can choose the Swift versione (Swift 2.3 or Swift 3.0). Select Swift 2.3 (it's fully compatible with Swift 2.3 but does support the new iOS API). Then, again, fix the errors manually.
Solution 3
Open the library you are using and use Xcode 8 to upgrade that to Swift 3.0. This is a temporary solution until the developer of that library will provide the upgraded code
When you open your project with Xcode 8.0 for the first time, you will be prompted via the migration assistant to do a migration pass. The assistant can also be invoked manually from the menu
Edit -> Convert -> To Current Swift Syntax…
If you upgraded code e.g. 2.3 to 3.0 and now want downgrade to 2.3 you can use above. If any errors occur copy your code from last commit in your repository and it should work fine.