I tested out some code in a playground and it works as I would expect.
I built an extremely basic (one function, one button, one textfield) project to test the code in and it doesn't work – in fact it hangs up (beach balling).
What might cause this to happen? Both the playground and the project import Cocoa and Foundation.
The code is below.
It appears to get hung up on this line:
let data = pipe.fileHandleForReading.readDataToEndOfFile()
Here's the code as it is written in the playground (and copied into the project):
import Cocoa
import Foundation
// *** Getting exiftool version number
func exiftoolVersion() -> String {
let task = Process()
let pipe = Pipe()
task.standardOutput = pipe
task.arguments = ["-ver"]
task.executableURL = URL(fileURLWithPath: "/usr/local/bin/exiftool")
do {
try task.run()
task.waitUntilExit()
}
catch {
}
let data = pipe.fileHandleForReading.readDataToEndOfFile()
var output = String(data: data, encoding: .utf8)!
output = output.filter { !$0.isWhitespace }
return output
}