Most will probably know this anyway, however a few amongst the forum users may not know how effective the use of Extension for Text can be.
If you have many text strings in your app that have a style modifier applied, or you want to have a consistent look for the text strings across several apps that you are developing, then Extension can help you.
You can create a new Swift file - 'TextStyles.swift'
import SwiftUI
extension Text {
func deepRedTextStyle() -> some View {
self.foregroundColor(.red)
.italic()
.opacity(0.7)
.font(.subheadline)
}
func captionTextStyle() -> some View {
self.foregroundColor(.secondary)
.font(.caption)
}
}
// Then in the app you can use it as follows
Text("What is this?")
.deepRedTextStyle()
Text("Great job!")
.captionTextStyle()
Text("Thank you")
.deepRedTextStyle()
Anything that you can add to Text as a modifier, can be used in the Extension definitions.
Not only will it make text appearance be consistent in your app, and between your apps, it will also save coding lines and make the code clearer and easier to follow.