Skip to content

[SR-9918] FileHandle should conform to TextOutputStream #3538

Open
@sindresorhus

Description

@sindresorhus
Previous ID SR-9918
Radar rdar://problem/48032239
Original Reporter @sindresorhus
Type New Feature
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels New Feature
Assignee None
Priority Medium

md5: 1fba25807ce87df0c8054a24e5f11a3f

Issue Description:

That would make it easier to work with stdout, stderr, and other file handles. For example, using stderr with `print()` [1].

Currently, every project has to include this extension:

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

And then it can be used like this:

var standardError = FileHandle.standardError
print("foo", to: &standardError)

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions