Skip to content

Why not use @ViewBuilder instead of eraseToAnyView? #3

Open
@Josscii

Description

@Josscii

public func applyIf<M: View, A: View>(
_ condition: Bool,
modifier: (Self) -> M,
else alternativeModifier: (Self) -> A
) -> some View {
if condition {
return modifier(self).eraseToAnyView()
}
else {
return alternativeModifier(self).eraseToAnyView()
}
}

Is there a specific reason? AnyView seems not good at performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions