sooon
sooon

Reputation: 4878

Swift Package Manager - How to use it

I have a project that I want to use this package in my app. I googled and follow the instructions:

//in Terminal

? mkdir SGLMath
? cd SGLMath
? swift package init --type executable

Then I open the package.swift file and change to this:

// swift-tools-version:3.1

import PackageDescription

    let package = Package(
        name: "SGLMath",
        dependencies: [
            .Package(url: "https://github.com/SwiftGL/Math.git", majorVersion: 1)
        ]
    )

then Terminal:

? swift package fetch

Then I got this error:

error: the package has an unsupported layout, unexpected source file(s) found: /Users/xuanxi/SGLMath/.build/checkouts/Math.git-9167533630816302265/Tests/EqualWithAccuracy.swift, /Users/xuanxi/SGLMath/.build/checkouts/Math.git-9167533630816302265/Tests/FunctionsTests.swift, /Users/xuanxi/SGLMath/.build/checkouts/Math.git-9167533630816302265/Tests/Matrix2x2Tests.swift, /Users/xuanxi/SGLMath/.build/checkouts/Math.git-9167533630816302265/Tests/Matrix3x3Tests.swift, /Users/xuanxi/SGLMath/.build/checkouts/Math.git-9167533630816302265/Tests/Matrix4x4Tests.swift, /Users/xuanxi/SGLMath/.build/checkouts/Math.git-9167533630816302265/Tests/SwizzleTests.swift, /Users/xuanxi/SGLMath/.build/checkouts/Math.git-9167533630816302265/Tests/Vector2Tests.swift, /Users/xuanxi/SGLMath/.build/checkouts/Math.git-9167533630816302265/Tests/Vector4Tests.swift, /Users/xuanxi/SGLMath/.build/checkouts/Math.git-9167533630816302265/Tests/glmMatrixTests.swift

fix: move the file(s) inside a module

How can I resolve this?

  1. What if I want to add this package into my existing Xcode project?

Upvotes: 2

Views: 1357

Answers (1)

Vadim Eisenberg
Vadim Eisenberg

Reputation: 3427

  1. The project https://github.com/SwiftGL/Math.git does not have the correct Swift Package Manager format. The files in Tests directory should be in a directory with name: the module name + "Tests" ending appended, in this case SGLMathTests. You can fork the project and fix it or ask the author to fix it.
  2. To use the project with Xcode, once you fix it:

    a. Run swift package generate-xcodeproj. It will generate an Xcode project with the package.

    b. Create an Xcode workspace and add to it your existing Xcode project and the generated project in the previous step. Add the framework with the package from the generated project to your existing Xcode project as a dependency. This should work.

Upvotes: 1

Related Questions