[swift-evolution] [proposal] Allow function argument type to be omitted when passing a default value from which it can be inferred

Haravikk swift-evolution at haravikk.me
Wed May 11 08:03:40 CDT 2016


> On 11 May 2016, at 13:49, Vladimir.S via swift-evolution <swift-evolution at swift.org> wrote:
> 
> public var a = 10 // OK, all is clear here
> public var a = "sdfsdf" // OK
> public var a = someFunction() // not OK - add type of `a` explicitly

I’m not clear on why you think the third one isn’t okay; Xcode can tell you what the type was inferred to be, you can check the function signature (alt - click the name) which will tell the type that it returns, as well as call up any documentation about what it does.

The only reason you would need to set a type on the property is if you know you’ll need to assign something less specific in future, e.g- a parent type in a class hierarchy.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160511/db1bae4d/attachment.html>


More information about the swift-evolution mailing list