Alamofire: Build error with Swift Package Manager

I’m using Xcode 8 and the official SPM. I try to use Alamofire through SPM:

import PackageDescription

let package = Package(
    name: "swift-playground",
    dependencies: [
        .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 4)
    ]
)

However, swift build gives me a lot of errors:

Cloning https://github.com/Alamofire/Alamofire.git
HEAD is now at 5fe5b20 Added release notes to the CHANGELOG and bumped the version to 4.0.0.
Resolved version: 4.0.0
Compile Swift Module 'Alamofire' (17 sources)
/Users/skyline/Projects/Github/swift-playground/Packages/Alamofire-4.0.0/Source/DispatchQueue+Alamofire.swift:33:25: error: use of undeclared type 'TimeInterval'
    func after(_ delay: TimeInterval, execute closure: @escaping () -> Void) {
                        ^~~~~~~~~~~~
/Users/skyline/Projects/Github/swift-playground/Packages/Alamofire-4.0.0/Source/SessionDelegate.swift:111:50: error: 'URLSessionStreamTask' is only available on OS X 10.11 or newer
    open var streamTaskReadClosed: ((URLSession, URLSessionStreamTask) -> Void)?
                                                 ^
/Users/skyline/Projects/Github/swift-playground/Packages/Alamofire-4.0.0/Source/SessionDelegate.swift:111:50: note: add @available attribute to enclosing class
    open var streamTaskReadClosed: ((URLSession, URLSessionStreamTask) -> Void)?
                                                 ^
/Users/skyline/Projects/Github/swift-playground/Packages/Alamofire-4.0.0/Source/SessionDelegate.swift:114:51: error: 'URLSessionStreamTask' is only available on OS X 10.11 or newer

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 16 (4 by maintainers)

Most upvoted comments

So I’ve spent some time on swift-users trying to get to the bottom of how this all is supposed to work and I think I have it pretty much figured out. Although there are still some serious shortcomings, you can at least get things to work. If you follow these steps, you can get things working.

Using SPM with Alamofire

  1. Clone Alamofire locally and tag the master branch as 4.0.2

This is necessary to pick up a change I made in the Package.swift file that hasn’t been released yet

  1. Create an example project
  2. Create a Package.swift file for your project similar to the following:
import PackageDescription

let package = Package(
    name: "SPMTester", 
    dependencies: [
        .Package(url: "/Users/cnoon/Desktop/Alamofire", "4.0.2")
    ]
)
  1. Create your main.swift file in Sources
import Alamofire
import Foundation

Alamofire.request("https://httpbin.org/get").responseJSON { response in
    debugPrint(response)
    exit(0)
}

RunLoop.current.run()
  1. Create a Configuration.xcconfig file to override the deployment target
SDKROOT = macosx
MACOSX_DEPLOYMENT_TARGET = 10.11
  1. Generate the Xcode project for your new example

$ swift package generate-xcodeproj --verbose --xcconfig-overrides ./Configuration.xcconfig --output ./SPMTester.xcodeproj

  1. Open the Xcode project, navigate to the project (not target) settings and delete the MACOSX_DEPLOYMENT_TARGET setting so the xcconfig value can be picked up by the project
  2. Build and run

Here’s an example of a small SPMTester project that I put together.


Summary

Now this is certainly still WAY more painful than it should be, but at least it’s actually up and running. Once the community adds more features this process should get easier and easier.

From those errors it appears you aren’t using Xcode 8. Alamofire 4 requires Xcode 8. If you need to keep using Xcode 7, please use Alamofire 3.5.0.

@cnoon thx for the temporary solution. +1 for this issue.

@cnoon so there is no known solution that supports swift build from the command line without using Xcode?

@jshier Please consider reopening this. I think maybe #1549 is also related to this.

I’m indeed using Xcode 8 and Swift 3. I think there may be some kind of bug in SPM.