小编Jun*_*hoi的帖子

swift 中 CommandLine.arguments 和 Processinfo.processinfo.arguments 之间的区别

我想知道如何将这些不同 的CommandLine ProcessInfo

let elements = CommandLine.arguments
let elements = Processinfo.processinfo.arguments
Run Code Online (Sandbox Code Playgroud)

在我看来,ProcessInfo 的论点具有命令行的所有概念。所以处理争论没有区别。

下面的代码使用 CommandLine.arguments,用于练习读写文件。

如果我将 Processinfo.processinfo.arguments 放在 CommanLine.arguments 的位置。没有改变。

static func makeInOutFile() -> (inputFile: String, outputFile: String)? {
    let elements = CommandLine.arguments
    let inputFile: String
    let outputFile: String
    switch elements.count {
    case 2:
        inputFile = elements[1]
        outputFile = Message.ofDefaultJSONFileName.description
        return (inputFile: inputFile, outputFile: outputFile)
    case 3:
        inputFile = elements[1]
        outputFile = elements[2]
        return (inputFile: inputFile, outputFile: outputFile)
    default:
        print (Message.ofFailedProcessingFile)
        return nil
    }
}
Run Code Online (Sandbox Code Playgroud)

command-line-arguments swift

4
推荐指数
1
解决办法
1320
查看次数

标签 统计

command-line-arguments ×1

swift ×1