3

I'm new with Swift and all this tools. I've tried to look for guides but they didn't help me. I wanna try to work with packages in VS code.So I decided to add a SwiftyJSON package. This is my Package.swift file:

import PackageDescription

let package = Package(
    name: "SwiftyJSON",
    dependencies: [
        .package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", from: "4.0.0"),
    ]
)

And I got an error error: no such module 'PackageDescription' import PackageDescription For VS Code I use an extension Swift and package dependencies. It automatically detects a package but when I save my Package.swift file terminal gives me an error:

> Executing task: swift package resolve <

'swiftpackages': error: the manifest is missing a Swift tools version specification; 

consider prepending to the manifest '// swift-tools-version: 5.6' to 
specify the current Swift toolchain version as the lowest Swift version
supported by the project; 

if such a specification already exists, consider moving it to the top
of the manifest, or prepending it with '//' to help Swift Package
Manager find it

The terminal process "/opt/homebrew/bin/zsh '-c', 'swift package
resolve'" failed to launch (exit code: 1).

How I can add packages in VS code?

KeoFoxy
  • 41
  • 3
  • Use Xcode to create packages. – cora May 20 '22 at 17:21
  • You mean package file? And then open it with VS code for the next use? – KeoFoxy May 20 '22 at 17:23
  • What does the surrounding context look like? `Package.swift` only does anything within a Swift package, which you make with `swift package init
    `
    – Alexander May 20 '22 at 17:30
  • Although the library you link to has XCode 8 I'm assuming you're just using VSCode as an editor. In which case you may find it useful to install the Swift VS Code extension which has a command for resolving all dependencies in the file you have open. That should include installing the `PackageDescription` Swift package. You can find the VS Code extension in the extensions tab or via the web here: https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang – RustyFluff May 21 '22 at 06:32
  • @RustyFluff I use this extension but when I save my `Package.swift` file terminal shows me an error ``` Executing task: swift package resolve 'swiftpackages': error: the manifest is missing a Swift tools version specification; consider prepending to the manifest '// swift-tools-version: 5.6' to specify the current Swift toolchain version as the lowest Swift version supported by the project; if such a specification already exists, consider moving it to the top of the manifest, or prepending it with '//' to help Swift Package Manager find it ``` So I cant add my package to Dependencies – KeoFoxy May 21 '22 at 10:11
  • @RustyFluff Finally I added a package to dependencies but when I try to import it terminal gives an error `import SwiftyJSON` `error: no such module 'SwiftyJSON' import SwiftyJSON` – KeoFoxy May 21 '22 at 18:49

0 Answers0