0
votes

I have a Xcode project which uses cocoapods to embed Alamofire library. My Podfile looks like this:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
pod 'Alamofire', '~> 3.3'

Now, I need to make use of another library, which incidentally is a MongoDB driver for Swift. Given I am relatively new in the iOS development field, it would be convenient for me to add just another line in the Podfile mentioning the MongoDB driver, however, it is not available as a cocoapod. On the driver's GitHub repository, it is specified that in order to install it, one just have to add the library to the Package.swift file.

It took me some time to figure how to install the Swift Package Manager, but I eventually did it. Now, as far as the official documentation states,

The Package Manager will be released with Swift 3 and is currently only available with the Swift 3 development snapshots.

and following the installation instructions from the SPM official github repo, I downloaded and installed the latest development snapshot (as of 2016-04-12). Moreover, I followed the rest of the relevant instructions for XCode 7.3 (my version) and now when I run swift build --version the terminal displays the expected output Apple Swift Package Manager 0.1

When I run xcrun --find swift it displays:

/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-04-12-a.xctoolchain/usr/bin/swift

When I run swift --version it displays:

Apple Swift version 3.0-dev (LLVM 752e1430fc, Clang 3987718dae, Swift 36739f7b57)

Sorry for such a verbose introduction, but here is the problem:

When I change from the Xcode 7.3 default toolchain to XCode Swift Development Snapshot in order to use the SPM and when I try to build the project after restarting Xcode(in order for the toolchain changes to take place), the compiler generates a lot of errors with respect to the Alamofire library, which had worked before, when using the default toolchain.

Xcode errors

Here is the question: How to solve these issues in order for me to import the necessary MongoDB driver using SPM and in parallel to import Alamofire pod without getting those errors?

My assumption is that Alamofire was written in Swift 2.2 but in order to run SPM and build the project, swift 3.0 dev is required, so, the errors may be related to the conflicting versions of swift. Correct me please if I am wrong.

I have a limited understanding of how the internals of SPM work and how to connect SPM with Xcode 7.3 even if I read the corresponding documentation from the official Apple docs, so any help/explanation is appreciated!

1

1 Answers

0
votes

You can't mix Swift 2 and Swift 3. So you can’t do what you want. Find a mongo library that targets Swift 2 or use a fork of Alamofire that is already ported to Swift 3.

Now, even then I'm not sure if you'll be able to do what you want, you weren't specific about how you are using SwiftPM, but it does not yet support iOS development, so…