How to Clear the Terminal Screen in Swift

How to clear the Terminal screen in Swift?

Use the built-in clear command either with system

system("clear")

or popen (ask Google)

Alternatively, simulate the pressing of Ctrl+L using AppleScript via the command line:

osascript -e 'tell app "terminal" to tell app "system events" to keystroke "l" using {control down}'

EDIT: system is no longer available in newer verions of Swift. See Rudolf Adamkovič's answer.

Is it possible to clear the console in swift?

There are two appraoches i can think of that might work for you.
The first one is already an answer to a similar question:

print("\u{001B}[2J")

The second way would to just print many newlines until the old output is off screen.

How to clear console programmatically in Xcode?

Maybe you could use the "Auto Clear Debug Console" setting in the Xcode Preferences...

Don't know if this answers your question?

How can I clear previous output in Terminal in Mac OS X?

To clear the terminal manually:

+K

Command+K for newer keyboards

To clear the terminal from within a shell script;

/usr/bin/osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "k" using command down'

Clearing Navigation Stack in Swift

So I ended up having to do it programmatically by popping back to the first controller and then replacing from the funnel head to the dashboard head:

func bookingCompleteAcknowledged(){
//remove the popup controller
dismissViewControllerAnimated(true, completion: nil)
//remove current controller
dismissViewControllerAnimated(true, completion: nil)

if let topController = UIApplication.sharedApplication().keyWindow?.rootViewController {

if let navcontroller = topController.childViewControllers[0] as? UINavigationController{
navcontroller.popToRootViewControllerAnimated(false)

if let funnelcontroller = navcontroller.childViewControllers[0] as? FunnelController {
funnelcontroller.removeFromParentViewController();
funnelcontroller.view.removeFromSuperview();

let revealController = self.storyboard?.instantiateViewControllerWithIdentifier("DashboardController") as! SWRevealViewController

navcontroller.addChildViewController(revealController)
navcontroller.view.addSubview(revealController.view)
}
}
}

}


Related Topics



Leave a reply



Submit