4

I am trying to install SocketIO into my swift 4 iOS project using the swift package manager. The Package.swift file looks like this:

// 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: "MyApp",

    dependencies: [
        .package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMajor(from: "12.0.0"))
    ]

)

On command line when I type 'swift build' the packages are fetched but there is an error:

"warning: no targets to build in package"

When I try to import SocketIO in my app I get:

"No such module 'SocketIO'" error.

This is my first time using Package Manager. Just wondering how to resolve this and whether or not I need to add targets myself in the Package.swift file?

Not sure if I set up Package Manager correctly initially. Also wondering if there is a way to uninstall and reinstall Package Manger? Or is it just a matter of replacing the Package.swift file in the project directory.

alionthego
  • 8,508
  • 9
  • 52
  • 125

2 Answers2

1

Could you try the following:

  • Use .Package instead of .package
  • Use majorVersion: 12, minor: 0 instead of .upToNextMajor

Code:

import PackageDescription

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

Output:

If successfully built the following will be created:

  • Package.resolved will contain the packages used
  • .build hidden directory is created, these will contain the build files.

Tested on:

  • Swift 4.0

Refer:

https://swift.org/getting-started/#using-the-package-manager

user1046037
  • 16,755
  • 12
  • 92
  • 138
  • error: type 'Package.Dependency' has no member 'Package' .Package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMajor(from: "12.0.0")) – alionthego Oct 02 '17 at 08:48
  • Which version of Swift are you using ? Are you on linux or Mac ? – user1046037 Oct 02 '17 at 08:48
  • Mac and swift 4.0 – alionthego Oct 02 '17 at 08:49
  • 2
    Couple of points to note, Swift Package Manager only supports Mac app at the moment – user1046037 Oct 02 '17 at 08:50
  • oh.... I didn't know that. Maybe that's why the dependencies are not being linked. Thanks very much. – alionthego Oct 02 '17 at 08:52
  • No, that's not the reason why you get that error. Why are you using `.upToNextMajor` ? Can you see the answer that I have provided – user1046037 Oct 02 '17 at 08:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/155744/discussion-between-user1046037-and-alionthego). – user1046037 Oct 02 '17 at 08:53
  • I just want the SocketIO framework in my chat application. All was working fine prior to Swift 4 where previously I manually added the files to my project. Not I can no longer manually add them because of some frameworks I also need so I need to use Cocoapods or Package Manager. I wanted to avoid Cocoapods. I tried your solution but it didn't work. The dependency is from the SocketIO GitHub page – alionthego Oct 02 '17 at 09:21
  • the Package.resolved and .build are created with my original code, however the import SocketIO returns an error – alionthego Oct 02 '17 at 09:27
0

I had the same issue.

I found documentation for SPM v4.

By this link

So, you should try this:

// 1.0.0 ..< 2.0.0
.package(url: "/SwiftyJSON", from: "1.0.0"),

// 1.2.0 ..< 2.0.0
.package(url: "/SwiftyJSON", from: "1.2.0"),

// 1.5.8 ..< 2.0.0
.package(url: "/SwiftyJSON", from: "1.5.8"),

// 1.5.8 ..< 2.0.0
.package(url: "/SwiftyJSON", .upToNextMajor(from: "1.5.8")),

// 1.5.8 ..< 1.6.0
.package(url: "/SwiftyJSON", .upToNextMinor(from: "1.5.8")),

// 1.5.8
.package(url: "/SwiftyJSON", .exact("1.5.8")),

// Constraint to an arbitrary open range.
.package(url: "/SwiftyJSON", "1.2.3"..<"1.2.6"),

// Constraint to an arbitrary closed range.
.package(url: "/SwiftyJSON", "1.2.3"..."1.2.8"),

// Branch and revision.
.package(url: "/SwiftyJSON", .branch("develop")),
.package(url: "/SwiftyJSON", .revision("e74b07278b926c9ec6f9643455ea00d1ce04a021"))
Alex Motor
  • 928
  • 5
  • 20