YogeshChauhan . com

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)
}
amazon

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 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

PHP Variables ScopePHPWhat are keys in React?ReactGive buttons accessible namesUI/UXHow to Block IPs and User Agents using code in Drupal or WordPress?DrupalWhat is the difference between float and double?MiscHow to change perception and behavior of a person for acceptance of new systems?MiscHow to Display Related Posts in WordPress?WordPressWhat happens when we add Numbers and Strings in JavaScript?JavaScriptHow to Pop an Alert Box in PHP?JavaScriptHow to control file extensions with an .htaccess file?MiscHow to add CurrencyPipe in TypeScript file in Angular 9 Project?AngularIntroduction to Angular modules Part 2: NgModules and componentsAngular