if var testStream = OutputStream(path: aPath) {
print("Testing custom output", toStream: &testStream)
print("Hello ", terminator: "", toStream: &testStream)
print("World", toStream: &testStream)
print("Output sent to \(testStream.path)")
} else {
print("Failed to create custom output")
}
Am I right in assuming this construction will not compile in Swift 3.0? And if so, how should I best recommend re-configuration. I assume the preferred route would be either:
if let outputStream = OutputStream(path: aPath) {
var testStream = outputStream
print("Testing custom output", toStream: &testStream)
print("Hello ", terminator: "", toStream: &testStream)
print("World", toStream: &testStream)
print("Output sent to \(testStream.path)")
} else {
print("Failed to create custom output")
}
Or using shadowing to mimics the "if let x = x" pattern that has become conventional:
if let outputStream = OutputStream(path: aPath) {
var outputStream = outputStream
print("Testing custom output", toStream: &outputStream)
print("Hello ", terminator: "", toStream: &outputStream)
print("World", toStream: &outputStream)
print("Output sent to \(outputStream.path)")
} else {
print("Failed to create custom output")
}
if var testStream = OutputStream(path: aPath) {
print("Testing custom output", toStream: &testStream)
print("Hello ", terminator: "", toStream: &testStream)
print("World", toStream: &testStream)
print("Output sent to \(testStream.path)")
} else {
print("Failed to create custom output")
}
Am I right in assuming this construction will not compile in Swift 3.0? And if so, how should I best recommend re-configuration. I assume the preferred route would be either:
if let outputStream = OutputStream(path: aPath) {
var testStream = outputStream
print("Testing custom output", toStream: &testStream)
print("Hello ", terminator: "", toStream: &testStream)
print("World", toStream: &testStream)
print("Output sent to \(testStream.path)")
} else {
print("Failed to create custom output")
}
Or using shadowing to mimics the "if let x = x" pattern that has become conventional:
if let outputStream = OutputStream(path: aPath) {
var outputStream = outputStream
print("Testing custom output", toStream: &outputStream)
print("Hello ", terminator: "", toStream: &outputStream)
print("World", toStream: &outputStream)
print("Output sent to \(outputStream.path)")
} else {
print("Failed to create custom output")
}
if var testStream = OutputStream(path: aPath) {
print("Testing custom output", toStream: &testStream)
print("Hello ", terminator: "", toStream: &testStream)
print("World", toStream: &testStream)
print("Output sent to \(testStream.path)")
} else {
print("Failed to create custom output")
}
Am I right in assuming this construction will not compile in Swift 3.0? And if so, how should I best recommend re-configuration. I assume the preferred route would be either:
if let outputStream = OutputStream(path: aPath) {
var testStream = outputStream
print("Testing custom output", toStream: &testStream)
print("Hello ", terminator: "", toStream: &testStream)
print("World", toStream: &testStream)
print("Output sent to \(testStream.path)")
} else {
print("Failed to create custom output")
}
Or using shadowing to mimics the "if let x = x" pattern that has become conventional:
if let outputStream = OutputStream(path: aPath) {
var outputStream = outputStream
print("Testing custom output", toStream: &outputStream)
print("Hello ", terminator: "", toStream: &outputStream)
print("World", toStream: &outputStream)
print("Output sent to \(outputStream.path)")
} else {
print("Failed to create custom output")
}
if var testStream = OutputStream(path: aPath) {
print("Testing custom output", toStream: &testStream)
What sticks out to me here is, why is OutputStream a value type at all? Does it have some sensible copying behavior? It looks like an OutputStream more or less represents an open file, which seems like a perfect use case for a reference type.
One reason is that we wanted to be able to use a String as an OutputStream.
-Dave
···
On Dec 18, 2015, at 5:53 AM, Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org> wrote:
if var testStream = OutputStream(path: aPath) {
print("Testing custom output", toStream: &testStream)
What sticks out to me here is, why is OutputStream a value type at all? Does it have some sensible copying behavior? It looks like an OutputStream more or less represents an open file, which seems like a perfect use case for a reference type.