I need to restart my app in case I reload something that will require a start from the very beginning. I tried this
let path = NSBundle.mainBundle().resourcePath!.stringByDeletingLastPathComponent.stringByDeletingLastPathComponent
let task = NSTask()
task.launchPath = "open"
task.arguments = [path]
task.launch()
exit(0)
but I get an error upon the open
launch path not accessible
Though the problem itself was trivial (forgot the path) I leave question and answer in case someone else needs the same functionality.
let path = NSBundle.mainBundle().resourcePath!.stringByDeletingLastPathComponent.stringByDeletingLastPathComponent
let task = NSTask()
task.launchPath = "/usr/bin/open"
task.arguments = [path]
task.launch()
exit(0)
Edit (daily Swift syntax change for Sw3; works also for 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With