[swift-evolution] Be able to initialise empty dict with array constrcutor

James Campbell james at supmenow.com
Tue Jan 5 06:39:35 CST 2016


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] = []*

If this isn't possible then I wouldn't mind having some way of telling the
compiler to auto create it like so:

*var distanceCache: [Int: Int] ()*

or

*var distanceCache: [Int: Int] = new Dictionary*

or even:

*var distanceCache: [Int: Int] = auto*

*auto var distanceCache: [Int: Int]*

(auto short for auto create)


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.
-- 
 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/fdd718c8/attachment.html>


More information about the swift-evolution mailing list