Skip to content

Instantly share code, notes, and snippets.

@HereOrCode
Created August 30, 2021 07:26
Show Gist options
  • Save HereOrCode/2b291c60de6a9b7e6fc1e3b3fcfddcad to your computer and use it in GitHub Desktop.
Save HereOrCode/2b291c60de6a9b7e6fc1e3b3fcfddcad to your computer and use it in GitHub Desktop.
SwiftUI-Debug
//
// Utils.swift
// SwiftUIAppleDemo
//
// Created by Apple on 2021/8/30.
//
import Foundation
import SwiftUI
/**
Building SwiftUI debugging utilities | Swift by Sundell
https://www.swiftbysundell.com/articles/building-swiftui-debugging-utilities/
*/
extension View {
func print(_ value: Any) -> Self {
Swift.print(value)
return self
}
func debugAction(_ closure: () -> Void) -> Self {
#if DEBUG
closure()
#endif
return self
}
func debugPrint(_ value: Any) -> Self {
debugAction {
print(value)
}
}
func debugModifier<T: View>(_ modifier: (Self) -> T) -> some View {
#if DEBUG
return modifier(self)
#else
return self
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment