How to read Standard Input in Swift?
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 {

Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress? Mar 3 substring() Method in JavaScript Mar 3 Window setInterval() Method in JavaScript Mar 2 How to zoom an element on hover using CSS? Mar 2 the box-sizing property in CSS

You might also like these

The flex-grow, flex-shrink and flex-basis Properties in CSSCSSHow to Find the Highest (or Lowest) Number in an Array in JavaScript?JavaScriptHow to Use Aggregate Functions (MIN, MAX, SUM, AVG, COUNT) to Summarize Data in SQL?SQL/MySQL3 JavaScript methods to use when you want to go back and forth in historyJavaScriptAlways add associated labels to your Form elementsUI/UXHow to get start index and end index (as int) of substring in Swift?SwiftHow to create Glowing Text using CSS?CSSWhat is the difference between float and double?MiscHow to Display Related Posts in WordPress?WordPressWordPress get_posts ExamplesWordPressIntroduction to components and templates Part 2: Templates and viewsAngularAttributes and Properties in JavaScript and HTMLHTML