diff --git a/Sources/ViewCondition/ViewCondition.swift b/Sources/ViewCondition/ViewCondition.swift index b5c87fe..e629d64 100644 --- a/Sources/ViewCondition/ViewCondition.swift +++ b/Sources/ViewCondition/ViewCondition.swift @@ -15,6 +15,7 @@ import SwiftUI /// /// Methods: /// - `if(_:content:)`: Applies a modifier to the view based on a condition. +/// - `if(os:content:)`: Applies a modifier to the view based on the operating system. /// - `visible(if:removeCompletely:)`: Conditionally shows or hides the view based on a Boolean condition. /// - `visible(on:)`: Conditionally shows or hides the view based on the operating system. /// - `hide(if:removeCompletely:)`: Conditionally hides or removes the view based on a Boolean condition. @@ -39,6 +40,24 @@ public extension View { } } + /// Applies a modifier to the view based on the operating system. + /// + /// This method allows for conditional modification of a view based on the operating system. It internally + /// utilizes `if(_:content:)` to apply the modification. + /// + /// - Parameters: + /// - os: The operating system to check against. + /// - content: A closure that modifies the view. + /// - Returns: A modified view for the specified OS; otherwise, the original view. + @ViewBuilder + func `if`(os: OperatingSystem, content: (Self) -> Content) -> some View { + #if os(iOS) + self.if(os == .iOS, content: content) + #elseif os(macOS) + self.if(os == .macOS, content: content) + #endif + } + /// Controls the view's visibility, with an option to remove it when not visible. /// /// This method conditionally displays the view. If the `condition` is false,