Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run Cocoapods from Swift
func runCocoaPods() {
DispatchQueue.global(qos: .userInitiated).async {
let process = Process()
// The trick is launching a proper login shell that hosts the task in question
// so that the environment is being initialized correctly
// `-l` forces a login shell
// `-c` tells bash to run a specific command automatically
process.launchPath = "/bin/bash"
process.currentDirectoryPath = "/Users/terhechte/Dev/tmp/testRunCocoaPods"
process.arguments = [
"-l",
"-c",
"pod search --no-ansi --simple afnetworking"
]
let outputPipe = Pipe()
process.standardOutput = outputPipe
process.launch()
guard let output = String(data: outputPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) else {
return
}
print(output)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.