2

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.

  • 1
    Hope [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 Answers1

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