Swift Package Manager

2018-07-19  本文已影响0人  alex_zn

Swift Package Manager

Linux swift 安装
// 1, 安装clang编译器
sudo apt-get install clang
// 2, 直接指定目录
export PATH=/path/to/Swift/usr/bin:"${PATH}"

创建项目
// 创建目录名
mkdir MyApp
// 创建包
swift package init
// 
├── Package.swift
├── README.md
├── Sources
│   └── MyApp
│       └── MyApp.swift
└── Tests
    ├── LinuxMain.swift
    └── MyAppTests
        └── MyAppTests.swift
// 编译包
swift build
// 实时编译(main)运行
swift package init --type executable
// 运行
swift run MyApp
// 导出xcode工程
swift package generate-xcodeproj
// 依赖模块
let package = Package(
    name: "SPMDemo",
    dependencies: [
         .Package(url: "https://github.com/Alamofire/Alamofire.git", Version(4,7,0))
    ]
)

创建module

// 创建目录名
mkdir MyMoudle
// 创建包
swift package init --type library
// 添加tag
git tag 1.0.0 
git push origin --tags

// Package.swift
import PackageDescription

let package = Package(
    name: "testmoudle",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "testmoudle",
            targets: ["testmoudle"]),
    ],
    dependencies: [
        
        // 外部依赖
        .Package(url: "https://github.com/Alamofire/Alamofire.git", Version(4,7,0)),
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "testmoudle",
            dependencies: []),
        .testTarget(
            name: "testmoudleTests",
            dependencies: ["testmoudle"]),
    ]
)
上一篇下一篇

猜你喜欢

热点阅读