Alamofire gets added as a dependency in Package.swift :
// swift-tools-version:4.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "Foo", dependencies: [ .package(url: "https://github.com/Alamofire/Alamofire.git", from: "4.0.0") ], targets: [ .target( name: "Foo", dependencies: ["Alamofire"]), ] )
Then I add the example code to main.swift :
import Alamofire print("Hello, world!") Alamofire.request("https://httpbin.org/get").responseJSON < response in print("Request: \(String(describing: response.request))") // original url request print("Response: \(String(describing: response.response))") // http url response print("Result: \(response.result)") // response serialization result if let json = response.result.value < print("JSON: \(json)") // serialized json response >if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) < print("Data: \(utf8Text)") // original server data as UTF8 string >> print("Goodbye, world!")
After that I try to run it:
[u@h ~/swift/Foo]$ swift run Fetching https://github.com/Alamofire/Alamofire.git Cloning https://github.com/Alamofire/Alamofire.git Resolving https://github.com/Alamofire/Alamofire.git at 4.6.0 Compile Swift Module 'Alamofire' (17 sources) Compile Swift Module 'Foo' (1 sources) Linking ./.build/x86_64-apple-macosx10.10/debug/Foo Hello, world! Goodbye, world!
As you can see, none of the print statements in the Alamofire example code gets executed. The request does not get executed either, which can be observed when the Alamofire.request call points to a local web server.