What does it mean for Self{Self()}

I am currently doing the Scrumdinger tutorial, but I am stuck with this code static var trailingIcon: Self{Self()}. I am not quite sure the meaning of this code.

This is a computed variable on the type which returns a new instance of the type using it's init().

something like

static var computedTypeProperty:String {
    return "Test"
}

You had a detailed answer here: https://developer.apple.com/forums/thread/705545

  • static, which means it is a class value, not an instance value.

It will be called as LabelStyle.trailingIcon

  • trailingIcon is a computed var.

So { Self() } is not a closure but the returned value.

It is equivalent to

static var trailingIcon: Self { 
   get {
      return Self()
  }
}

trailingIcon: Self means trailingIcon is of type Self.

What does it mean for Self{Self()}
 
 
Q