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?
I know this post is old, but I ran into it looking for something else and you were so close! What was missing on your Package.swift file was the declaration of what version of swift tools that Package.swift was written to conform to. That line is needed at the top of every Package.swift file.
So closer to right, but still missing things would be:
The quickest way to start a new package in VSCode with a correct Package.swift is to:
swift package init --type library
will start a new library package - If not interested in a library there are others,swift package init --help
will show the available templates.Once you have YOUR new package you can do what you've already started to do, add dependencies on others like SwiftJSON.
Now this all depends on you having the right tools installed. Since you're using homebrew you're likely on a Mac. Installing Xcode will get you everything you need. You never have to use it if you don't want. That's the easiest. The homebrew version of swift is frequently behind.
I use VSCode to write Swift both on a Mac and Linux so if that's the IDE you want to use it's very doable.
++1 to using the Swift VSCode extesion by the server working group: https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Anyway I hope you stuck with it and figured it out. Happy 2024!