🤖Compiler Directives
Compilation Condition: #if
#if DEBUG
#if <compilation flag> 👉 Feature flags in Swift
#if targetEnvironment( )
func log(_ expression: @autoclosure () -> Any) {
// print a given expression only within debug builds
#if DEBUG
print(expression())
#endif
}struct EditorView: View {
//...
var body: some View {
#if os(tvOS)
CanvasView()
#else
CanvasView().gesture(DragGesture().onChanged { state in
// ...
})
#endif
// ...
}
}func setupTabBarController(_ controller: UITabBarController) {
var viewControllers = [UIViewController]()
#if targetEnvironment(simulator)
viewControllers.append(DebugViewController())
#endif
controller.viewControllers = viewControllers
}Last updated
Was this helpful?