Skip to content

A pipe for streaming text from the command line into Swift scripts.

License

Notifications You must be signed in to change notification settings

otto-schnurr/FileInput-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FileInput

A pipe for streaming text from the command line into Swift scripts.

Update: Use readLine()

My hope is for this framework to eventually become redundant and obsolete. The makers of Swift could come up with an elegant way to pump lines of text into scripts.

In September 2015, the engineers at Apple granted my wish with the addition of readLine() to Swift 2 (details here). Their implementation is robust, simple to use and highly recommended. I plan to use it for my own scripts.

This repository will be maintained but mostly as an academic exercise.

If you're looking for an arcane excuse to use FileInput, obtaining the file path of each line of text is a minor detail that can be interesting in certain cases.

myScript.swift a.txt b.txt c.txt

However, processing multiple files is easily accomplished with readLine().

cat a.txt b.txt c.txt | myScript.swift

Usage

The interface is borrowed from python.

#!/usr/bin/swift -F <path-to-FileInput.framework>
import FileInput
for line in input() {
	process(line)
}

More documentation here.

Dependencies

Requires Xcode 7.3 or later.

Installation

% git clone [email protected]:otto-schnurr/FileInput-swift.git
...
% cd FileInput-swift
% xcodebuild
...

Move ./build/Release/FileInput.framework to a convenient path for your Swift scripts to reference.

important: If you plan to ship this framework in a binary, Apple recommends recompiling Swift frameworks with the same version of Xcode as your binary.

License

MIT License, see http://opensource.org/licenses/MIT

About

A pipe for streaming text from the command line into Swift scripts.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published