我需要重启我的应用程序,以防我重新加载需要从头开始的东西。我试过这个
let path = NSBundle.mainBundle().resourcePath!.stringByDeletingLastPathComponent.stringByDeletingLastPathComponent
let task = NSTask()
task.launchPath = "open"
task.arguments = [path]
task.launch()
exit(0)
但我在open
无法访问启动路径
答案 0 :(得分:3)
虽然问题本身是微不足道的(忘了路径)但我会留下问题和答案,以防其他人需要相同的功能。
let path = NSBundle.mainBundle().resourcePath!.stringByDeletingLastPathComponent.stringByDeletingLastPathComponent
let task = NSTask()
task.launchPath = "/usr/bin/open"
task.arguments = [path]
task.launch()
exit(0)
编辑(Sw3的每日Swift语法更改;也适用于Sw4):
let url = URL(fileURLWithPath: Bundle.main.resourcePath!)
let path = url.deletingLastPathComponent().deletingLastPathComponent().absoluteString
let task = Process()
task.launchPath = "/usr/bin/open"
task.arguments = [path]
task.launch()
exit(0)