如何在Swift中访问程序参数? [英] How do I access program arguments in Swift?
本文介绍了如何在Swift中访问程序参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C和衍生产品 argc
和 argv
(和 envp
)参数到它们的入口点函数,但Swift没有一个适当的:顶级代码只是代码,它没有参数。
C and derivatives have argc
and argv
(and envp
) parameters to their entry point functions, but Swift doesn't have one proper: top-level code is just code and it doesn't have parameters.
可以在Swift程序中访问等效的 argc
和 argv
?
How can one access the equivalent of argc
and argv
in a Swift program?
推荐答案
作为参考(自Swift 3.0 August 4快照以来):
Process 刚刚重命名为 CommandLine
For reference (since Swift 3.0 August 4 snapshot):
Process was just renamed into CommandLine
let arguments = CommandLine.arguments
(由于某种原因,这未在 changelog )
(for some reason this wasn't mentioned on the changelog)
这篇关于如何在Swift中访问程序参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文