上下文:我想使用CryptoSwift创建一个简单的Swift命令行工具 我对Xcode和Swift(以及MacOS!)相对较新。
配置:
- MacOS High Sierra 10.13.2
- Xcode:9.2
步骤:
~/Documents
将main.swift填入:
import Foundation
import CryptoSwift
print("Hello, World!")
let bytes:Array<UInt8> = [0x01, 0x02, 0x03]
let digest = Digest.md5(bytes)
打开shell并进入~/Documents/cryptodemo
git submodule add https://github.com/krzyzanowskim/CryptoSwift.git
CryptoSwift.xcodeproj
文件拖到我的Xcode项目在Xcode中,我进入我的项目Build Phase
然后我建立它。我有这个错误:
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
的存档答案 0 :(得分:0)
答案 1 :(得分:0)
我设法使用第三方Swift库构建命令行工具的唯一方法是使用Swift Package Manager (SPM)。
使用SPM的Swift项目示例(可以使用Process: Xcode [70544]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 9.3 (14154)
Build Info: IDEFrameworks-14154000000000000~2
App Item ID: 497799835
App External ID: 826408812
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [70544]
User ID: 501
Date/Time: 2018-05-21 14:04:50.053 -0400
OS Version: Mac OS X 10.13.4 (17E199)
Report Version: 12
Anonymous UUID: 335CE1E7-B5AB-F717-E6D0-019AF52B3708
Sleep/Wake UUID: 7824F1AB-C514-4609-A447-F15EA9C86C84
Time Awake Since Boot: 99000 seconds
Time Since Wake: 1800 seconds
System Integrity Protection: enabled
Crashed Thread: 18 Dispatch queue: XCUIRecorder_iOS.processingQueue
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
ProductBuildVersion: 9E145
UNCAUGHT EXCEPTION (NSInternalInconsistencyException): First snapshot has type Other: Other, 0x7f9d8c64aaf0, {{0.0, 0.0}, {0.0, 0.0}}
UserInfo: (null)
Hints:
Backtrace:
0 __exceptionPreprocess (in CoreFoundation)
1 DVTFailureHintExceptionPreprocessor (in DVTFoundation)
2 objc_exception_throw (in libobjc.A.dylib)
3 +[NSException raise:format:arguments:] (in CoreFoundation)
4 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] (in Foundation)
5 +[XCUIRecorderNodeFinder nodeToFindElementForSnapshots:language:platform:] (in XCTest)
6 -[XCUIRecorderUtilities nodeToFindElementForSnapshots:] (in XCTest)
7 __177-[XCUIRecorder_iOS _XCT_recordedEventNames:timestamp:duration:startLocation:startElementSnapshot:startApplicationSnapshot:endLocation:endElementSnapshot:endApplicationSnapshot:]_block_invoke (in XCTest)
8 _dispatch_call_block_and_release (in libdispatch.dylib)
9 _dispatch_client_callout (in libdispatch.dylib)
10 _dispatch_queue_serial_drain (in libdispatch.dylib)
11 _dispatch_queue_invoke (in libdispatch.dylib)
12 _dispatch_root_queue_drain_deferred_wlh (in libdispatch.dylib)
13 _dispatch_workloop_worker_thread (in libdispatch.dylib)
14 _pthread_wqthread (in libsystem_pthread.dylib)
15 start_wqthread (in libsystem_pthread.dylib)
ëØ$ïˇˇ
abort() called
Application Specific Signatures:
NSInternalInconsistencyException
生成):
swift package init --type executable
可以使用以下命令从此SPM生成Xcode项目:// 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" ]),
]
)