[swift-evolution] 3.0 if-var workaround construction question
David Owens II
david at owensd.io
Thu Dec 17 13:44:41 CST 2015
That’s a bummer. :(
> On Dec 17, 2015, at 10:35 AM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>
> Yeah, declaring the `var` immediately inside the `if` block is equivalent to the deprecated `if var` form.
>
> -Joe
>
>> On Dec 17, 2015, at 10:32 AM, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>> My new linter picked up the following as a problem for Swift 3.0, because of my interpretation of the rules in https://github.com/apple/swift-evolution/blob/master/proposals/0003-remove-var-parameters-patterns.md <https://github.com/apple/swift-evolution/blob/master/proposals/0003-remove-var-parameters-patterns.md>
>>
>> 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")
>> }
>>
>> Thanks in advance for insight.
>>
>> -- E
>>
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151217/f81a1ad2/attachment.html>
More information about the swift-evolution
mailing list