欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Swift Package Manager

程序员文章站 2022-05-31 09:28:38
...

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"]),
    ]
)

转载于:https://www.jianshu.com/p/2c4901341896