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
Finish Asynchronous Task in Firebase With Swift
Swift: How to Detect Linear Type Barcodes
How to Save Data from Cloud Firestore to a Variable in Swift
Get Description of Emoji Character
Ios 15 Navigation Bar Transparent
Nsdateformatter Return Wrong Date + Swift
Module Compiled With Swift 3.0 Cannot Be Imported in Swift 3.0.1
Swift - How to Mutate a Struct Object When Iterating Over It
No Such Module 'Restkit' With Cocoapods and Swift
Multiple Workers in Swift Command Line Tool
Xcode 7 Compile Error: "Command Failed Due to Signal: Segmentation Fault: 11"
Get the Top Viewcontroller in iOS Swift
In Swift, What Does the ! Symbol Mean in a Function Signature
How to Use the Appropriate Color Class For the Current Platform
Swift Optional Inout Parameters and Nil
How to "Strongify" Optional Self Using Guard in Swift 2.0