For some reason the Process class is not registering as apart of the Foundation import even though it is clearly stated Here in the Apple Swift language API Library that the Process class is a part of Foundation.
For example:
import Foundation
let task = Process()
throws the error:
use of unresolved identifier Process
I have tried using NSTask, which is what the Process class used to be called but that does not work either.
This is what I am trying to do:
import Foundation
var str = "let str = \"Hello\"\nprintln(\"\\(str) world\")\n"
let task = Process()
task.launchPath = "/usr/bin/swift"
let outpipe = Pipe()
let inpipe = Pipe()
inpipe.fileHandleForWriting.write(str.data(using: String.Encoding.utf8, allowLossyConversion: true)!)
task.standardInput = inpipe
task.standardOutput = outpipe
task.launch()
task.waitUntilExit()
task.standardInput = Pipe()
let data = outpipe.fileHandleForReading.readDataToEndOfFile()
let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)! as String
which creates the “str” constant from text. And yes I know that this is forbidden by Apple but it is not for an app on the App Store.
So basically I need to know what NSTask has been changed to in swift 3.0
I am using the latest version of Xcode (8.1) and the latest version of Swift (3.0). Please help!