Does Swift have an implicit Object Initializer, like in C#? -


in c#, have object initializers, so:

    person obj = new person     {         firstname = "craig",         lastname = "playstead",     }; 

does swift have this?

as example, have code:

var config = indicatesconfig() config.name = nslocalizedstring(localizable.folders, comment: "").uppercasestring config.style = .detailheader return config 

but along lines of:

var config = indicatesconfig() {     name = nslocalizedstring(localizable.folders, comment: "").uppercasestring     style = .detailheader } 

thank you!

edit:

i'm not referencing explicit definition of class initialisers. please bear in mind syntax shown in c# example.

not such. if create custom struct, swift will, under conditions, create default memberwise initializer close you're looking for. otherwise, don't think there's way implement such feature, since swift lacks with keyword new instance's scope.

update: close can get, defining custom operator:

infix operator <| { }  func <|<t>(decl: @autoclosure () -> t, f: t -> () ) -> t {     let obj = decl()     f(obj)     return obj }  let label = uilabel() <| {     $0.frame = cgrect(x: 10, y: 10, width: 300, height: 25)     $0.text = "hello"     $0.enabled = false }  println(label) // <uilabel: 0x7fb46240b210; frame = (10 10; 300 25); text = 'hello'; userinteractionenabled = no; layer = <_uilabellayer: 0x7fb46240c2b0>> 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -