[swift-users] syntax suggestion
Jordan Rose
jordan_rose at apple.com
Fri Oct 28 17:31:30 CDT 2016
Hi, Rangding. This is a known issue, tracked by SR-1846 <https://bugs.swift.org/browse/SR-1846>. Essentially the compiler is not smart enough to know that you mean the existing function 'data' rather than the variable you are defining.
Best,
Jordan
> On Oct 27, 2016, at 19:06, 张让定 via swift-users <swift-users at swift.org> wrote:
>
> 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
>
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161028/86676291/attachment.html>
More information about the swift-users
mailing list