0

背景:我想使用CryptoSwift创建一个简单的 Swift 命令行工具 我对 Xcode 和 Swift(以及 MacOS!)相对较新。

配置:
- MacOS High Sierra 10.13.2
- Xcode:9.2

脚步:

  1. 我开始 Xcode
  2. 为 MacOS 创建一个新项目“命令行工具”
  3. 我的项目的选项:
    • 产品名称:密码演示
    • 组织标识符:com.demo
    • 语言斯威夫特
  4. 我将项目创建为~/Documents
  5. 填写我的 main.swift :

    import Foundation
    import CryptoSwift
    
    print("Hello, World!")
    
    let bytes:Array<UInt8> = [0x01, 0x02, 0x03]
    let digest = Digest.md5(bytes)
    
  6. 打开外壳进入~/Documents/cryptodemo

  7. 添加 CryptoSwift 作为项目自述文件定义的子模块,使用:git submodule add https://github.com/krzyzanowskim/CryptoSwift.git
  8. 打开 Finder 并将 CryptoSwift.xcodeproj 文件拖到我的 Xcode 项目中
  9. 在 Xcode 中,我进入我的项目Build Phase

    • 我添加CryptoSwift为目标依赖项
    • 我添加CryptoSwift.frameworkLink Binaries with Libraries
    • 我添加CryptoSwift.frameworkCopy Files
      • 目的地:Framework
      • 子路径:(空) 在此处输入图像描述
  10. 然后我建立它。我有这个错误:

    Check dependencies
    
    Unable to run command 'PBXCp CryptoSwift.framework' - this target might include its own product.
    Unable to run command 'CodeSign A' - this target might include its own product.
    

    在此处输入图像描述

这是项目cryptodemo.zip的存档

4

2 回答 2

0

删除第 9 步并将 CryptoSwift.framework 添加到“ Linked Frameworks and Libraries

在此处输入图像描述

像这儿: 在此处输入图像描述

于 2018-02-07T03:06:42.200 回答
0

我设法使用第三方 Swift 库构建命令行工具的唯一方法是使用Swift Package Manager (SPM)

使用 SPM 的 Swift 项目示例(可以使用 生成swift package init --type executable):

// 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: “mytool”,
    dependencies: [
        .package(url: "https://github.com/myfreeweb/SwiftCBOR.git", .branch("master")),
    ],
    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: “mytool”,
            dependencies: [ "SwiftCBOR" ]),
    ]
)

可以使用以下 SPM 生成 Xcode 项目:swift package generate-xcodeproj

于 2018-05-20T21:41:06.260 回答