Reputation: 500
Given I have a simple View
like:
public struct MyView: View {
public var body: some View {
Text("My text 1")
Text("My text 1")
}
}
Is there an elegant way of setting a modifier on the View
's body (such as setting AccessibilityIdentifier
) straight in this struct without having to do this in the class that embeds MyView
or creating another View layer?
Upvotes: 0
Views: 38
Reputation: 285079
A possible way is to wrap the content of the body
in a Group
public struct MyView: View {
public var body: some View {
Group {
Text("My text 1")
Text("My text 1")
}
.font(.title)
}
}
Upvotes: 1