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 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

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 change style of all direct children of an element using jQuery?jQueryHow to vertically align a html radio button to it’s label?CSSA Quick Comparison of JOIN and Subquery in SQLSQL/MySQL5 Key Principles Of Good Website UsabilityUI/UXHow to use images instead of HTML radio buttons using CSS?CSSHigher Order Functions in JavaScript with ExamplesJavaScriptJavaScript Number MethodsJavaScriptHow to change perception and behavior of a person for acceptance of new systems?MiscellaneousSolution for the error Commit failed – exit code 1 received in Desktop GithubMiscellaneousHow to show slider value in HTML5 range input using JavaScript?HTMLLearn to Establish Connection using MySQLi (object-oriented), MySQLi (procedural) and PDO with Example CodePHPHTML canvas methodsHTML