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.
- I understand that this is about extending the type
LabelStyle. And from the docs, I understand thatwhere Self == TrailingIconLabelStylemeans that the extension will only take place onLabelStylein case the type isTrailingIconLabelStyle. Why do I have to create a separate extension? Why not addtrailingIcontoTrailingIconLabelStyledirectly? - Why is
trailingIconstatic. Doesn't that mean that all instances always reference the same value? - What does
Self { Self() }mean? I assume this is some closure that can also be written likeSelf(x in { Self() })or so. But I don't really get this.