Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sindresorhus opened this issue Feb 13, 2019 · 3 comments
Open

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

sindresorhus opened this issue Feb 13, 2019 · 3 comments

Comments

@sindresorhus
Copy link

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

@belkadan
Copy link

cc @millenomi, @milseman

@millenomi
Copy link
Contributor

I like it, and I'll see what timeframe can have this if we do it. But as with all requests that add API surface, we can take feedback, but promise nothing.

@milseman
Copy link
Mannequin

milseman mannequin commented Feb 13, 2019

SGTM. Also, it seems kinda weird that there's no way to access stderr in the standard library, and no way to name stdout/stderr.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants