[swift-evolution] It's the little things..
mac at johnholdsworth.com
Mon Dec 12 18:15:03 CST 2016
As the festive season approaches I thought I’d write a brain dump
of a few things I'd hope Santa could bring in his bag for Swift 3.1.
No big ideas, just things that bug me day to day and would be
backward source compatible.
I’m sure it’s been discussed before but I wish static and class vars and
functions were in scope for instance methods without having to prefix them
as they are in Java. I’d go further and say they should be available when
referring to an object outside the class as if they were instance methods
Occasionally I find myself wishing I could give a static variable function
or method scope i.e. declare it inside the function or method if there are
no other references to localise access.
I’d like to raise again the idea of optionality when referencing a key or
calling a function could be possible using a ? i.e instead of
let a = key != nil ? dict[key] : nil
you could just write:
let a = dict[key?]
let a = func( arg: argumentThatMayBeNull? ) // not called if argument is nil
As subscripts are functions these are probably the same thing.
One thing I encountered the recently writing a (bad) regular expression
library was that I wish getters were not required for subscript overloads.
In the library I wanted to write multiple setters for different types being
assigned but you only want one declared getter or you get ambiguities.
And of course, multi-line string literals using either “””long string””” or <<“HEREDOC”.
More information about the swift-evolution