I'm looking to write a command line program, and one thing I used a lot in C++ was system("clear");
to clear the screen of the terminal window. I can use print("\u{001B}[2J") to clear the screen, but I still would like to be able to have my program "type" into the terminal.
Asked
Active
Viewed 728 times
2

NeighborKid01
- 21
- 4
-
1Hope [this](http://stackoverflow.com/questions/33448353/how-to-clear-the-terminal-screen-in-swift) helps – GAVD Jan 20 '17 at 01:54
-
If you're using Swift 3, `system` will be unavailable. You will need to use the `posix_spawn` APIs or `NSTask`. – JAL Jan 20 '17 at 02:03
1 Answers
1
Just use Process
from Foundation:
import Foundation
func clear() {
let p = Process()
p.launchPath = "/usr/bin/clear"
p.launch()
}
clear()

Alexander
- 59,041
- 12
- 98
- 151
-
I tried this, but when I ran the program, the first time I had a readLine() the program crashed immediately. – NeighborKid01 Feb 16 '17 at 21:36