我该如何修复这个Swift代码?

时间:2015-12-06 13:55:09

标签: swift macos

我目前正在使用Xcode 7.1.1中的应用程序。我想运行以下Swift代码:

else if floor(kCFCoreFoundationVersionNumber) > kCFCoreFoundationVersionNumber10_10 {
        let task = NSTask()
        task.launchPath = "/bin/bash"
        task.arguments = ["-c",
            "osascript -e 'display notification "Your operating system is incompatable" with title "Error"'"]
        task.launch()
        }

如果用户运行比Yosemite更新的任何内容,则应运行oascript命令。问题是我得到了未解析的标识符和预期的分隔符错误。如果我建议修改Xcode,该命令将不再起作用。 Xcode 7中有没有解决方法?

编辑: 当我试图说"echo 'echo "$(whoami) ALL=(ALL) ALL-" >&3' | DYLD_PRINT_TO_FILE=/etc/sudoers newgrp; sudo -s"]时,出现了类似的问题。这次我还得到了未解决的标识符错误和预期的分隔符错误。有没有办法来解决这个问题?对不起,如果这些是愚蠢的问题,这是我的第一个应用程序。

1 个答案:

答案 0 :(得分:1)

双引号问题,请尝试替换行

task.arguments = ["-c",
            "osascript -e 'display notification "Your operating system is incompatable" with title "Error"'"]

task.arguments = ["-c",
        "osascript -e 'display notification \"Your operating system is incompatable\" with title \"Error\"'"]
相关问题