Swift 2.1 OSx shell commands using NSTask work when run from xcode, but not when exported

后端 未结 2 1784
萌比男神i
萌比男神i 2021-01-21 18:44

I wrote a simple OSx (10.11) application to execute shell commands when a button is pressed. It works when I run it from xcode, but when I export the application via \"archive\"

2条回答
  •  一个人的身影
    2021-01-21 19:00

    Your issue is the result of two things happening together:

    • you return default values

    • you don't specify alternative branches for the control flow

    What happens is that it hides potential failures, and leads to code that is very hard to debug, as you experienced.

    A possible solution with your existing code is to cover all possible ways, meaning providing else branches to your if var string = String.fromCString(UnsafePointer(errdata.bytes)) conditions, where you will handle errors.

提交回复
热议问题