Yogesh Chauhan's Blog

How to read Standard Input in Swift?

in Swift on March 5, 2020

To read standard input in swift we will need to use readLine() function.

Function


readLine(strippingNewline:)

Returns a string read from standard input through the end of the current line or until EOF is reached.

Declaration


func readLine(strippingNewline: Bool = true) -> String?

Reading String


let string_input = readLine()
if let string_input = string_input {
    print(string_input) 
}

Reading Int


let number_input = Int(readLine()!)
if let number_input = number_input {
    print(number_input)
}

Reading Float


let number_input = Float(readLine()!)
if let number_input = number_input {
    print(number_input)
}

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
Casting in PostgreSQLPostgresHow to force your website to load securely with an .htaccess file?MiscellaneousIs monitoring an employee’s work on a computer a desirable or undesirable activity?MiscellaneousHAVING Clause in Postgres with Examples in All Aggregate FunctionsPostgresSelf-Driving and Intelligent NetworksMiscellaneousHow to make a web page look good on any device?HTMLHow to show widgets on the Appearance tab in WordPress?WordPressColumn and Table Alias in PostgresPostgresHow to add a new role in WordPress?WordPressHow to create a full screen loader using CSS and JavaScript?CSSHow to set up the local environment and workspace for Angular development?AngularHow to find the HCF or GCD and LCM of two given numbers using Swift?Swift