What does Self { Self() } mean?

Hi, I'm following the iOS AppDev Tutorials by Apple, and stumbled upon the following lines of code:

struct TrailingIconLabelStyle: LabelStyle {
  func makeBody(configuration: Configuration) -> some View {
    HStack {
      configuration.title
      configuration.icon
    }
  }
}

extension LabelStyle where Self == TrailingIconLabelStyle {
  static var trailingIcon: Self { Self() }
}

And I have a few questions here.

  1. I understand that this is about extending the type LabelStyle. And from the docs, I understand that where Self == TrailingIconLabelStyle means that the extension will only take place on LabelStyle in case the type is TrailingIconLabelStyle. Why do I have to create a separate extension? Why not add trailingIcon to TrailingIconLabelStyle directly?
  2. Why is trailingIcon static. Doesn't that mean that all instances always reference the same value?
  3. What does Self { Self() } mean? I assume this is some closure that can also be written like Self(x in { Self() }) or so. But I don't really get this.
  • 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 Self { Self() } mean?
 
 
Q