diff --git a/Sources/OpenSwiftUI/Core/Log/Log.swift b/Sources/OpenSwiftUI/Core/Log/Log.swift index e8737f07..76b56872 100644 --- a/Sources/OpenSwiftUI/Core/Log/Log.swift +++ b/Sources/OpenSwiftUI/Core/Log/Log.swift @@ -6,7 +6,7 @@ // Status: Complete #if OPENSWIFTUI_SWIFT_LOG -internal import Logging +import Logging #else import os #if DEBUG @@ -27,6 +27,7 @@ public let dso = { () -> UnsafeMutableRawPointer in #endif #endif +@usableFromInline enum Log { static func internalWarning( _ message: @autoclosure () -> String, @@ -37,10 +38,10 @@ enum Log { } #if OPENSWIFTUI_SWIFT_LOG + @usableFromInline static let runtimeIssuesLog = Logger(label: "OpenSwiftUI") @_transparent - @inline(__always) static func runtimeIssues( _ message: @autoclosure () -> StaticString, _ args: @autoclosure () -> [CVarArg] = [] @@ -48,20 +49,21 @@ enum Log { runtimeIssuesLog.log(level: .critical, "\(message())") } #else - static let runtimeIssuesLog = OSLog(subsystem: "com.apple.runtime-issues", category: "OpenSwiftUI") - + + // Audited for RELEASE_2023 + @usableFromInline + static var runtimeIssuesLog = OSLog(subsystem: "com.apple.runtime-issues", category: "OpenSwiftUI") + @_transparent - @inline(__always) static func runtimeIssues( _ message: @autoclosure () -> StaticString, _ args: @autoclosure () -> [CVarArg] = [] ) { #if DEBUG - let message = message() unsafeBitCast( os_log as (OSLogType, UnsafeRawPointer, OSLog, StaticString, CVarArg...) -> Void, to: ((OSLogType, UnsafeRawPointer, OSLog, StaticString, [CVarArg]) -> Void).self - )(.fault, dso, runtimeIssuesLog, message, args()) + )(.fault, dso, runtimeIssuesLog, message(), args()) #else os_log(.fault, log: runtimeIssuesLog, message(), args()) #endif diff --git a/Sources/OpenSwiftUI/Data/Environment/Environment.swift b/Sources/OpenSwiftUI/Data/Environment/Environment.swift index 2fe799a8..d5c9dd69 100644 --- a/Sources/OpenSwiftUI/Data/Environment/Environment.swift +++ b/Sources/OpenSwiftUI/Data/Environment/Environment.swift @@ -7,6 +7,11 @@ // ID: 7B48F30970137591804EEB8D0D309152 internal import OpenGraphShims +#if OPENSWIFTUI_SWIFT_LOG +import Logging +#else +import os +#endif /// A property wrapper that reads a value from a view's environment. /// @@ -189,12 +194,38 @@ public struct Environment: DynamicProperty { /// } /// } /// + // Audited for RELEASE_2023 @inlinable public var wrappedValue: Value { switch content { case let .value(value): return value case let .keyPath(keyPath): + #if OPENSWIFTUI_SWIFT_LOG + Log.runtimeIssuesLog.log(level: .critical, """ + Accessing Environment<\(Value.self)>'s value outside of \ + being installed on a View. \ + This will always read the default value \ + and will not update. + """) + #else + if #available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) { + os_log(.fault, log: Log.runtimeIssuesLog, """ + Accessing Environment<\(Value.self)>'s value outside of \ + being installed on a View. \ + This will always read the default value \ + and will not update. + """) + } else { + os_log(.fault, log: Log.runtimeIssuesLog, """ + Accessing Environment's value outside of being \ + installed on a View. \ + This will always read the default value \ + and will not update. + """) + } + #endif + // not bound to a view, return the default value. return EnvironmentValues()[keyPath: keyPath] } }