View

extension View

Generic extension to apply conditional transforms.

Source: https://www.avanderlee.com/swiftui/conditional-view-modifier/

  • Applies the given transform if the given condition evaluates to true.

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content>(_ condition: Bool, @ViewBuilder transform: (Self) -> Content) -> some View where Content : View

    Parameters

    condition

    The condition to evaluate.

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if the condition is true.

  • Applies the given transform if the given condition evaluates to true.

    Declaration

    Swift

    @ViewBuilder
    public func ifelse<IfContent, ElseContent>(_ condition: Bool, @ViewBuilder ifTransform: (Self) -> IfContent, elseTransform: (Self) -> ElseContent) -> some View where IfContent : View, ElseContent : View

    Parameters

    condition

    The condition to evaluate.

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if the condition is true.

  • Applies the given transform if the given condition evaluates to true.

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content, Item>(item: Item?, @ViewBuilder transform: (Self, Item) -> Content) -> some View where Content : View

    Parameters

    condition

    The condition to evaluate.

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if the condition is true.

  • Applies the given transform if all of the given values are not nil

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content: View, Item1, Item2>(
        items: (Optional<Item1>, Optional<Item2>),
        @ViewBuilder transform: (Self, (Item1, Item2)) -> Content
    ) -> some View

    Parameters

    items

    A tuple of values

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if all values exist

  • Applies the given transform if all of the given values are not nil

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content: View, Item1, Item2, Item3>(
        items: (Optional<Item1>, Optional<Item2>, Optional<Item3>),
        @ViewBuilder transform: (Self, (Item1, Item2, Item3)) -> Content
    ) -> some View

    Parameters

    items

    A tuple of values

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if all values exist

  • Applies the given transform if all of the given values are not nil

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content: View, Item1, Item2, Item3, Item4>(
        items: (Optional<Item1>, Optional<Item2>, Optional<Item3>, Optional<Item4>),
        @ViewBuilder transform: (Self, (Item1, Item2, Item3, Item4)) -> Content
    ) -> some View

    Parameters

    items

    A tuple of values

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if all values exist

  • Applies the given transform if all of the given values are not nil

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content: View, Item1, Item2, Item3, Item4, Item5>(
        items: (Optional<Item1>, Optional<Item2>, Optional<Item3>, Optional<Item4>, Optional<Item5>),
        @ViewBuilder transform: (Self, (Item1, Item2, Item3, Item4, Item5)) -> Content
    ) -> some View

    Parameters

    items

    A tuple of values

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if all values exist

  • Applies the given transform if all of the given values are not nil

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content: View, Item1, Item2, Item3, Item4, Item5, Item6>(
        items: (Optional<Item1>, Optional<Item2>, Optional<Item3>, Optional<Item4>, Optional<Item5>, Optional<Item6>),
        @ViewBuilder transform: (Self, (Item1, Item2, Item3, Item4, Item5, Item6)) -> Content
    ) -> some View

    Parameters

    items

    A tuple of values

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if all values exist

  • Applies the given transform if all of the given values are not nil

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content: View, Item1, Item2, Item3, Item4, Item5, Item6, Item7>(
        items: (Optional<Item1>, Optional<Item2>, Optional<Item3>, Optional<Item4>, Optional<Item5>, Optional<Item6>, Optional<Item7>),
        @ViewBuilder transform: (Self, (Item1, Item2, Item3, Item4, Item5, Item6, Item7)) -> Content
    ) -> some View

    Parameters

    items

    A tuple of values

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if all values exist

  • Applies the given transform if all of the given values are not nil

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content: View, Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8>(
        items: (Optional<Item1>, Optional<Item2>, Optional<Item3>, Optional<Item4>, Optional<Item5>, Optional<Item6>, Optional<Item7>, Optional<Item8>),
        @ViewBuilder transform: (Self, (Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8)) -> Content
    ) -> some View

    Parameters

    items

    A tuple of values

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if all values exist

  • Applies the given transform if all of the given values are not nil

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content: View, Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8, Item9>(
        items: (Optional<Item1>, Optional<Item2>, Optional<Item3>, Optional<Item4>, Optional<Item5>, Optional<Item6>, Optional<Item7>, Optional<Item8>, Optional<Item9>),
        @ViewBuilder transform: (Self, (Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8, Item9)) -> Content
    ) -> some View

    Parameters

    items

    A tuple of values

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if all values exist

  • Applies the given transform if all of the given values are not nil

    Declaration

    Swift

    @ViewBuilder
    public func `if`<Content: View, Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8, Item9, Item10>(
        items: (Optional<Item1>, Optional<Item2>, Optional<Item3>, Optional<Item4>, Optional<Item5>, Optional<Item6>, Optional<Item7>, Optional<Item8>, Optional<Item9>, Optional<Item10>),
        @ViewBuilder transform: (Self, (Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8, Item9, Item10)) -> Content
    ) -> some View

    Parameters

    items

    A tuple of values

    transform

    The transform to apply to the source View.

    Return Value

    Either the original View or the modified View if all values exist