Created
August 30, 2021 07:26
-
-
Save HereOrCode/2b291c60de6a9b7e6fc1e3b3fcfddcad to your computer and use it in GitHub Desktop.
SwiftUI-Debug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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