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.



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


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

Reading String

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

Reading Int

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

Reading Float

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

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
How to Use the EXISTS and NOT EXISTS Operator with a Subquery in SQL and MySQL?SQL/MySQLCheck if any column has NULL values in PostgresPostgresAccessing and Setting features of JavaScript ObjectsJavaScriptHow to create a simple tab interaction using CSS?CSS:in-range and :out-of-range selector in CSSCSSHow to hide a DIV on clicks outside of it using jQuery?jQueryHow to update database configurations in WordPress?WordPressRBV Framework and closing of big brandsMiscellaneousFilling a button background from left to right using CSSCSSHow to show confirmation alerts with OK and cancel buttons using Swift 5?SwiftCreate a simple bar chart and column chart using pure CSS gridCSSGlobal JavaScript methods to convert variables to numbersJavaScript