How do I access program arguments in Swift?

后端 未结 5 803
别跟我提以往
别跟我提以往 2020-12-01 03:11

C and derivatives have argc and argv (and envp) parameters to their entry point functions, but Swift doesn\'t have one proper: top-lev

5条回答
  •  不知归路
    2020-12-01 03:30

    As soon as your app is up I'd use the process info:

    let args = NSProcessInfo.processInfo().arguments
    print(args)
    

    Nothing unsafe there, very convenient.

    Note that you have to import Foundation (or Cocoa / UIKit).

提交回复
热议问题