[swift-users] Infer types of default function parameters

Kilian Koeltzsch me at kilian.io
Fri Mar 10 06:10:00 CST 2017

Hi all,

this is a rather minor nitpick, I'm just looking for some opinions on this.

Declaring a function that has default parameters currently looks like this:

func foo(bar: String = "baz") {

Now I'm wondering if there would be any problems if it were possible to omit the type annotation for default params and let Swift's type inference handle that.

func foo(bar = "baz") {

It feels to be equivalent to omitting type annotations with variable declarations. Obviously more complex types would still require annotations being specified. Off the top of my head I can't think of any negative ramifications this might bring, be it in simple function/method declarations or protocol extensions and elsewhere.
Any further input on this would be much appreciated :)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170310/17ce496f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170310/17ce496f/attachment.sig>

More information about the swift-users mailing list