Swift, code tutorial Raywenderlich

struct LabelStyle: ViewModifier {
func body(content: Content) -> some View{
return content
.foregroundColor(Color.white)
.shadow(color: Color.black, radius: 5, x:2,y:2)
.font(Font.custom(“Arial Rounded MT Bold”, size: 18))
}
}

How come we return content first, instead of last, if i put it last the whole thing breaks down

It is last.
.foregroundColor(Color.white)
.shadow(color: Color.black, radius: 5, x:2,y:2)
.font(Font.custom(“Arial Rounded MT Bold”, size: 18))
are modifiers on content

@simpleroger Thanks very much for your question!

@murf214 is correct. You are reading the line incorrectly. It has been written that way to make it easy for some to see the properties better. Here is the conventional way of writing out the return statement:

  return content.foregroundColor(Color.white).shadow(color: Color.black, radius: 5, x:2,y:2).font(Font.custom(“Arial Rounded MT Bold”, size: 18))

I hope this helps!

All the best!

This topic was automatically closed after 166 days. New replies are no longer allowed.