2

I am trying to add Socket.IO to my Xcode project. I am quite new to Swift Package Manager (Where are the days where we could just drop code in our project)

I created a Package.swift file containing the following as described here

import PackageDescription

    let package = Package(
        name: "socket.io-test",
        products: [
            .executable(name: "socket.io-test", targets: ["MyTarget"])
        ],
        dependencies: [
            .package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMinor(from: "14.0.0"))
        ],
        targets: [
            .target(name: "MyTarget", dependencies: ["SocketIO"], path: "./My/Target/Path/")
        ]
    )

I then opened my terminal and navigated to my folder containing both my project and my Package.swift file. (I am assuming it should be in my project folder)

I then ran the following command:

swift package resolve

This produced the following error:

error: manifest parse error(s): error: argument 'targets' must precede argument 'dependencies' targets: [ ~~~~^~~~~~~~~~

So, following the instruction given by the error, I moved my 'targets' above dependencies.

I ran the command again and I then received the following error:

error: manifest parse error(s): error: incorrect argument label in call (have 'name:products:targets:dependencies:', expected 'name:pkgConfig:targets:dependencies:') let package = Package( ^

Since the original example taken from the github page did not have the labels setup like this, I simply changed my code to the following, each time trying to add what the package manager suggested (Preceding one argument to another, adding additional arguments):

import PackageDescription

let package = Package(
    name: "socket.io-test",
    pkgConfig: nil,
    providers: nil,
    targets: [
        .target(name: "MyTarget", dependencies: ["SocketIO"], path: "./My/Target/Path/")
    ],
    dependencies: [
        .package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMinor(from: "14.0.0"))
    ],
    swiftLanguageVersions: nil,
    exclude: nil,
    products: [
        .executable(name: "socket.io-test", targets: ["MyTarget"])
    ]
)

However, now the package manager is telling me the following strange error:

error: manifest parse error(s): error: extra argument 'products' in call products: [ ^

So now I give up, as I am clearly getting nowhere. How can the 'products' argument not belong here? And why does nothing suggested by the package manager work? I am sure I am missing something small. Can someone please point me in the right direction?

I have also looked at the following websites for assistance, but still cannot get mine to work.

Swift.org https://medium.com/xcblog/apple-swift-package-manager-a-deep-dive-ebe6909a5284

Hope my question isn't too long and that someone will find the time to assist :)

EDIT

I changed the code to the following:

import PackageDescription

let package = Package(
    name: "socket.io-test",
    dependencies: [
    .Package(url: "https://github.com/socketio/socket.io-client-swift", majorVersion: 14)
    ]
)

And this seemed to have worked without errors. It placed a Package.resolved file in my project folder. I cannot find a reference to what this file is and I am still lost with regards to using Socket.IO in my project.

EDIT 2

I proceeded in using Carthage to import the frameworks. Got it setup in 15 minutes. As the is a different solution not relevant to my question, I decided to add it as an edit rather than an answer.

If anyone is still able to answer the above, please feel free for future reference and I will still test it, and accept if its working.

2
  • 1
    I believe SPM doesn't really play that nice with Xcode yet. I would personally just use Carthage or CocoaPods if you want to integrate it with your iOS project. Commented Jan 29, 2019 at 21:42
  • Thanks, I figured as much after struggling more than half my day. I installed Carthage, added the line to the Cartfile and had it imported in about 15 min. You’d think something from Apple will work better with Xcode. Commented Jan 29, 2019 at 21:48

1 Answer 1

4

You need to add this line to the top of your Package.swift

// swift-tools-version:4.2
Sign up to request clarification or add additional context in comments.

1 Comment

+1. Note that you should use the current Swift tools version supported for your version of Xcode and project to avoid build errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.