You want to create a Swift package that produces a library named Utils and depends on an external package Alamofire. Which Package.swift snippet correctly sets this up?
hard📝 Application Q15 of 15
Swift - Basics and Runtime
You want to create a Swift package that produces a library named Utils and depends on an external package Alamofire. Which Package.swift snippet correctly sets this up?
let package = Package(name: "Utils", dependencies: [.package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.0.0")], targets: [.target(name: "Utils", dependencies: ["Alamofire"])], products: [.library(name: "Utils", targets: ["Utils"])]) correctly specifies the dependency with URL and version using from: "5.0.0", which is required for versioning.
Step 2: Check targets and products
let package = Package(name: "Utils", dependencies: [.package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.0.0")], targets: [.target(name: "Utils", dependencies: ["Alamofire"])], products: [.library(name: "Utils", targets: ["Utils"])]) includes the dependency in the target's dependencies array and defines a library product named "Utils" targeting the "Utils" target.
Step 3: Compare other options
let package = Package(name: "Utils", targets: [.target(name: "Utils")], products: [.executable(name: "Utils", targets: ["Utils"])]) lacks dependencies and wrongly defines an executable product. let package = Package(name: "Utils", dependencies: [], targets: [.target(name: "Utils")], products: [.library(name: "Utils", targets: ["Utils"])]) has no dependencies. let package = Package(name: "Utils", dependencies: [.package(url: "https://github.com/Alamofire/Alamofire.git")], targets: [.target(name: "Utils")], products: [.library(name: "Utils", targets: ["Utils"])]) misses the version specifier for the dependency, which is required.