[swift-evolution] What about a VBA style with Statement?
Vladimir.S
svabox at gmail.com
Wed Apr 13 08:35:36 CDT 2016
I like this idea.
In Delphi(Pascal) there is also such construction
with someVar do
begin
end;
And it is very handy and is used a lot (usually if you need to set/read a
lot of properties of some object).
Additionally, I believe such construction prevents some possible mistakes
with used variable name, especially if there is a similar-named variables
in cod (sometimes because of code completion feature in editor) ex:
someVar1 = ...
someVar1....
someVar2 = ..
someVar2....
someVar1... << mistake
someVar2...
and if "with" construction were here:
with someVar2 {
.some...
var a = .another
etc
}
But the problem with "with" in Delphi is that it is not explicit what
method/property belongs to that someVar and what doesn't belong.
In Swift, such construction should force us to somehow be explicit
regarding what methods/props belongs to that someVar instance. Seems like
"dot" syntax looks OK.
Don't know if that could be implemented in Swift technically.
On 13.04.2016 16:15, 李海珍 via swift-evolution wrote:
> I recently learned some VBA and I found a very conveniently `with` statement.
>
> `with` statement can be helpful to set property for UIKit instance.
>
> for instance a UILabel instance `textLabel` ,with `with` statement we can
> set UILabel property like this
>
>
> ```swift
>
> with textLabel{
>
> .textAlignment= .Left
>
> .textColor= UIColor.darkTextColor()
>
> .font= UIFont.systemFontOfSize(15)
>
> }
>
> ```
>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
More information about the swift-evolution
mailing list