FileHandle should conform to TextOutputStream

Originator:sindresorhus
Number:rdar://48032239 Date Originated:13-Feb-2019 04:54 PM
Status:Open Resolved:
Product:macOS + SDK Product Version:Swift 4.2
Classification:Enhancement Reproducible:Always
 
Summary:
That would make it easier to work with stdout, stderr, and other file handles. For example, using stderr with `Swift.print()` [1].

Currently, every project has to include this extension:

```swift
extension FileHandle: TextOutputStream {
	public func write(_ string: String) {
		write(string.data(using: .utf8)!)
	}
}
```

[1]: https://forums.swift.org/t/rework-print-by-adding-observable-standardoutput-and-standarderror-streams-to-standard-library/7775/3

Steps to Reproduce:
 

Expected Results:
 

Actual Results:
 

Version:
Swift 4.2

Notes:
Relevant Stack Overflow question: https://stackoverflow.com/questions/24041554/how-can-i-output-to-stderr-with-swift

Comments

Swift issue

https://bugs.swift.org/browse/SR-9918

By sindresorhus at Feb. 13, 2019, 9:57 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!