簡體   English   中英

Swift-為什么Process.arguments返回空數組

[英]Swift - Why Process.arguments returns empty array

我正在iOS應用程序中進行一些UI測試,但看到了一些奇怪的行為。

在我的setUp()方法中,我向XCUIApplication().launchArguments添加了一些值,但是當我查詢以查看啟動參數時,我得到的是空數組。

這是我的setUp()方法的樣子:

override func setUp() {
    super.setUp()

    let application = XCUIApplication()
    application.launchArguments = ["USE_SERVER_DEBUG"]
    application.launch()
}

這是調用Process.arguments檢索參數的函數

func checkArguments(){
    let launchArguments = Process.arguments
    for index in 0 ..< launchArguments.count {
        let argument = launchArguments[index] as String

        if argument.compare("USE_DEBUG_SERVER") == NSComparisonResult.OrderedSame {
            // Do something
        }
    }
    return true
}

我不確定Process是您自己的類還是錯字,但是您應該使用NSProcessInfo

if NSProcessInfo.processInfo().arguments.contains("USE_SERVER_DEBUG") {
    // Do something
}

另外,我通常建議不要設置啟動參數。 相反,您應該附加它們。 但是,這比任何其他方法都是最佳實踐。

application.launchArguments += "USE_SERVER_DEBUG"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM