[swift-users] Initializing an empty dictionary
James Campbell
james at supmenow.com
Wed Mar 9 13:00:20 CST 2016
Hey Chris already solved this for 2.2, it will now give you a fix-it to use
[:]. So no need to file a bug :)
*___________________________________*
*James⎥Head of Trolls*
*james at supmenow.com <james at supmenow.com>⎥supmenow.com <http://supmenow.com>*
*Sup*
*Runway East *
*10 Finsbury Square*
*London*
* EC2A 1AF *
On Wed, Mar 9, 2016 at 6:54 PM, Adriano Ferreira via swift-users <
swift-users at swift.org> wrote:
> Thanks Dmitri, will do as you suggested.
>
> BTW, sorry for the typo... I actually intended "=" rather than “:", but
> luckily you got this :P
>
> Best,
>
> — A
>
> > On Mar 9, 2016, at 12:48 PM, Dmitri Gribenko <gribozavr at gmail.com>
> wrote:
> >
> > Hi Adriano,
> >
> > On Wed, Mar 9, 2016 at 8:45 AM, Adriano Ferreira via swift-users
> > <swift-users at swift.org> wrote:
> >> Hi everyone,
> >>
> >> Does anyone know why Swift won’t let me use the alternative way below to
> >> init the dictionary?
> >>
> >> public extension SequenceType where Self.Generator.Element: Hashable {
> >>
> >> @warn_unused_result
> >> func frequencies() -> [Self.Generator.Element: Int] {
> >> var dictionary: [Self.Generator.Element: Int] = [:]
> >> // var dictionary: Dictionary<Self.Generator.Element, Int>() //
> <<<
> >> Not allowed!
> >
> > It produces a bad error message, unfortunately. The issue is that you
> > have a ':' instead of '='.
> >
> > But, that also fails. Only after I remove 'Self.' the compiler accepts
> it:
> >
> > var dictionary = Dictionary<Generator.Element, Int>()
> >
> > I would recommend you to file two issues on bugs.swift.org, the first
> > one about a bad diagnostic for your code, and the second one about the
> > compiler rejecting "var dictionary =
> > Dictionary<Self.Generator.Element, Int>()" in the code above (when the
> > equal sign is used).
> >
> > Dmitri
> >
> > --
> > main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> > (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160309/1600f11c/attachment.html>
More information about the swift-users
mailing list