I want to develop an app to promote the experience when using terminal on Mac. And I want to get the current working directory (cwd) from terminal. How can I implement it?
I notice that the answer in Get terminal output after a command swift is really good but it seems that it still cannot resolve my problem perfectly. I learned Process().currentDirectoryPath
from Apple's document https://developer.apple.com/reference/foundation/process Does it do the trick that I need? Can I use it like the following?
let path = Process().currentDirectoryPath
I am very new to swift and Xcode, please help me! Thanks!
Update: Thank you guys! It seems that both
let path = fileManager.default.currentDirectoryPath
and the Process()
one temporarily work for me. Are there any differences between these two?
FileManager.default.currentDirectoryPath
?