9
9
internal import OpenGraphShims
10
10
import Foundation
11
11
12
+ // MARK: - printChanges
13
+
12
14
extension View {
13
15
public static func _printChanges( ) {
14
16
printChangedBodyProperties ( of: Self . self)
@@ -32,12 +34,75 @@ func printChangedBodyProperties<Body>(of type: Body.Type) {
32
34
print ( result)
33
35
}
34
36
37
+ // MARK: - logChanges
38
+
39
+ // Audited for RELEASE_2023
40
+
41
+ #if OPENSWIFTUI_SWIFT_LOG
42
+ import Logging
43
+
44
+ extension Logger {
45
+ static let changeBodyPropertiesLogger = Logger ( subsystem: " org.OpenSwiftUIProject.OpenSwiftUI " , category: " Changed Body Properties " )
46
+ }
47
+ #else
48
+ import os. log
49
+
50
+ @available ( iOS 14 . 0 , macOS 11 , * )
51
+ extension Logger {
52
+ static let changeBodyPropertiesLogger = Logger ( subsystem: " org.OpenSwiftUIProject.OpenSwiftUI " , category: " Changed Body Properties " )
53
+ }
54
+
55
+ extension OSLog {
56
+ static let changeBodyPropertiesLogger = OSLog ( subsystem: " org.OpenSwiftUIProject.OpenSwiftUI " , category: " Changed Body Properties " )
57
+ }
58
+ #endif
59
+
60
+ extension View {
61
+ public static func _logChanges( ) {
62
+ logChangedBodyProperties ( of: Self . self)
63
+ }
64
+ }
65
+
66
+ extension ViewModifier {
67
+ public static func _logChanges( ) {
68
+ logChangedBodyProperties ( of: Self . self)
69
+ }
70
+ }
71
+
72
+ func logChangedBodyProperties< Body> ( of type: Body . Type ) {
73
+ let properties = changedBodyProperties ( of: type)
74
+ let result = OGTypeID ( type) . description
75
+ if properties. isEmpty {
76
+ #if OPENSWIFTUI_SWIFT_LOG
77
+ Logger . changeBodyPropertiesLogger. info ( " \( result) : unchanged. " )
78
+ #else
79
+ if #available( iOS 14 . 0 , macOS 11 , * ) {
80
+ Logger . changeBodyPropertiesLogger. info ( " \( result, privacy: . public) : unchanged. " )
81
+ } else {
82
+ os_log ( " %{public}s: unchanged. " , log: . changeBodyPropertiesLogger, type: . info, result)
83
+ }
84
+ #endif
85
+ } else {
86
+ #if OPENSWIFTUI_SWIFT_LOG
87
+ Logger . changeBodyPropertiesLogger. info ( " \( result) : \( properties. joined ( separator: " , " ) ) changed. " )
88
+ #else
89
+ if #available( iOS 14 . 0 , macOS 11 , * ) {
90
+ Logger . changeBodyPropertiesLogger. info ( " \( result, privacy: . public) : \( properties. joined ( separator: " , " ) , privacy: . public) changed. " )
91
+ } else {
92
+ os_log ( " %{public}s: %{public}s changed. " , log: . changeBodyPropertiesLogger, type: . info, result, properties. joined ( separator: " , " ) )
93
+ }
94
+ #endif
95
+ }
96
+ }
97
+
98
+ // MARK: - changedBodyProperties
99
+
35
100
func changedBodyProperties< Body> ( of type: Body . Type ) -> [ String ] {
36
101
var index = 0
37
102
repeat {
38
103
let options = [
39
104
OGGraph . descriptionFormat. takeUnretainedValue ( ) : " stack/frame " ,
40
- " frame_index " : index
105
+ " frame_index " : index,
41
106
] as NSDictionary
42
107
guard let description = OGGraph . description ( nil , options: options) ,
43
108
let dict = description. takeUnretainedValue ( ) as? [ String : Any ] ,
@@ -69,23 +134,23 @@ func changedBodyProperties<Body>(of type: Body.Type) -> [String] {
69
134
let fields = DynamicPropertyCache . fields ( of: Body . self)
70
135
buffer. applyChanged { offset in
71
136
switch fields. layout {
72
- case . product( let fields) :
137
+ case let . product( fields) :
73
138
guard let field = fields. first ( where: { $0. offset == offset } ) ,
74
- let name = field. name,
75
- let property = String ( cString: name, encoding: . utf8) else {
139
+ let name = field. name,
140
+ let property = String ( cString: name, encoding: . utf8)
141
+ else {
76
142
properties. append ( " @ \( offset) " )
77
143
return
78
144
}
79
145
properties. append ( property)
80
- break
81
- case . sum( _, _) :
146
+ case . sum:
82
147
properties. append ( " @ \( offset) " )
83
- break
84
148
}
85
149
}
86
150
}
87
151
return properties
88
- } while ( index != 32 )
152
+ } while index != 32
89
153
return [ ]
90
154
}
155
+
91
156
#endif
0 commit comments