search

Home  >  Q&A  >  body text

ios - swift 包管理怎么用

请教一下,swift包管理怎么用?我创建了一个swift项目,然后在根目录创建了一个Package.swift文件,
代码如下:

import PackageDescription

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

但是这里“ PackageDescription”报错,系统提示没有这个库,使用swift build也无效。

这个是什么问题,请大神解答一下。

大家讲道理大家讲道理2892 days ago382

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:53:46

    First of all, my understanding is that SwiftPM (Swift Package Manager) is not used like this in Xcode. Instead, it is done directly from the command line.

    Official introduction:

    The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

    Probably means, you can directly use SwiftPM to download, compile, and link your Swift code and dependencies

    Currently (Xcode 7.3) installed on OS

    $ swift build
    error: unable to invoke subcommand: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build (No such file or directory)
    
    swift build 时会报错,如下:

    $ export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"

    所以,你需要去下载开发版本的 swift。以下为解决方案:

    安装

    1. 去官方下载 Swift Trunk Development (master) 版本(即 dev 版本, 与 Xcode 使用版本不冲突)。传送门

      • 下载下来应该是 swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-osx.pkgSo, you need to download the development version of swift. The following is the solution:

      • Installation
      1. Go to the official website to download the Swift Trunk Development (master) version (that is, the dev version, which does not conflict with the version used by Xcode). Portal

          The downloaded file should be swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-osx.pkg, which is about 200MB

      Configure the latest Swift version into environment variables. Open the command line and execute

      $ swift build --version
      Apple Swift Package Manager 0.1

      Then check if the installation is successful

      $ cd ~/Desktop
      $ mkdir helloSwiftPM 
      $ cd helloSwiftPM

      Use

      First, create an empty directory🎜

      $ swift build --init
      
      🎜Then, initialize this directory. 🎜
      $ swift build
      🎜Compile🎜
      $ .build/debug/helloSwiftPM
      Hello, world!
      🎜Run🎜 rrreee 🎜This is OK

      reply
      0
  • PHPz

    PHPz2017-04-17 17:53:46

    swift package generate-xcodeproj first generates the xcode project file. Then just open it.

    reply
    0
  • Cancelreply