[swift-evolution] Be able to initialise empty dict with array constrcutor
James Campbell
james at supmenow.com
Tue Jan 5 06:51:26 CST 2016
The problem for me is that is so counter intuitive I didn't even know you
could do that.
On Tue, Jan 5, 2016 at 12:50 PM, Jeremy Pereira <
jeremy.j.pereira at googlemail.com> wrote:
> I don’t understand what the problem is
>
> > On 5 Jan 2016, at 12:39, James Campbell via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > See this code:
> > var distanceCache: [Int: Int] = Dictionary<Int, Int>()
> >
> > It is very long and tedious to write especially if what I am storing
> changes.
> >
> > I propose we be allowed to do the following:
> > var distanceCache: [Int: Int] = []
>
> You can do
>
> var distanceCache: [Int: Int] = [:]
>
> Also
>
> var distanceCache2 = [Int: Int]()
>
>
> > Perhaps this dictionary syntax is just confusing and it was a bad idea
> to make it the same as an array. Most languages use "{" so why did swift
> choose to share "[" with arrays and dictionaries.
>
> It’s not the same, you need the colons inside. I imagine that braces were
> discarded on the grounds that it would confuse the compiler with respect to
> closures, for example
>
> var myClosure = {} // is a variable of type () -> ()
>
>
> >
> > --
> > Wizard
> > james at supmenow.com
> > +44 7523 279 698
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
--
Wizard
james at supmenow.com
+44 7523 279 698
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160105/fd5cb58d/attachment.html>
More information about the swift-evolution
mailing list