Skip to content
Otto Schnurr edited this page Sep 2, 2014 · 19 revisions

FileInput

Pump lines of text into Swift scripts.

Type

LineOfText

Declaration

typealias LineOfText = String

Discussion

A collection of characters typically ending with a newline. The last line of a file might not contain a newline.

The FileInput class is a Sequence of LineOfText objects.

Construction

input()

Parses input from the command line.

Declaration

func input() -> FileInput

Discussion

Returns a FileInput sequence that iterates over lines of all file paths listed in command line arguments. If that list is empty then standard input is used.

let lineCount = countElements( input() )
println( "\(lineCount) lines" )

A file path of "-" is replaced with standard input.

FileInput()

Constructs a sequence that iterates lines of standard input.

Declaration

init()

Discussion

Creating FileInput using this constructor:

var standardInput = FileInput()

is equivalent to using a "-" file path:

var equivalentInput = FileInput( filePath: "-" )

Clone this wiki locally