我正在编写一个快速的XCTest,我需要评估一个子过程。我想调用终端,将applescript的路径传递给终端并执行它。
我在快速测试文件中同时导入了UIKit和Foundation。当我编写一个常量(如:let task = NSTask() )时,NSClass没有在NSObject中引用,因此我得到了一条消息,即它是
未解析的非标识符NSTask的使用
如果我编写的let pipe = NSPipe()被引用并工作。为什么NSTask在导入UIkit和基金会之后无法访问?
发布于 2016-10-01 07:05:47
苹果公司改变了NSTask的API
现在执行cmd的方法是:
// Create a process (was NSTask on swift pre 3.0)
let task = Process()
// Set the task parameters
task.launchPath = "/bin/ls"
task.arguments = ["-laF@" , filePath]
// Create a Pipe and make the task
// put all the output there
let pipe = Pipe()
task.standardOutput = pipe
// Launch the task
task.launch()
// Get the data
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: String.Encoding.utf8)
print(output!)https://stackoverflow.com/questions/33743110
复制相似问题