[swift-users] syntax suggestion

张让定 love-nankai at 163.com
Thu Oct 27 21:06:02 CDT 2016


Dear Sir/madam,I have a fuction:

import Foundation

public func data(with string:String?) -> Data? {
    if let string = string {
        return string.data(using: String.Encoding.utf8)
    }
    return nil
}


When I use it like:

let data = data(with: "Hello")


There is a compile error: variable used within it's own initial value.

If write like:

let stringData = data(with: "Hello")


Everything is OK.

So I wonder why not support the syntax like:

let data = data(with: "Hello")


Yours sincerely
Rangding Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161028/9f501d2e/attachment.html>


More information about the swift-users mailing list