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 add Read More Read Less Button using JavaScript? #2 How to check if radio button is checked or not using JavaScript? #3 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #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
Observation of Human Behavior [Shopping Observation Example]MiscellaneousAlways add associated labels to your Form elementsUI/UXSolution to “Call to undefined function mysql_error()” in RevSlider WordPress PluginWordPressHow to check if the page is single post page in WordPress?WordPressControl rendering using CSS content-visibility propertyCSSWhat are Class Constants in PHP?PHPA complete diagram with building blocks of an Angular applicationAngularfirst-of-type and last-of-type selectors in CSSCSS2 Ways we can create an Array in JavaScriptJavaScriptThe 7 Security Objectives of Any Organization for IT and Network SecurityMiscellaneousHow to show widgets on the Appearance tab in WordPress?WordPressRelative Length Units in CSSCSS