diff --git a/Tests/ColorComponentsTests/XCHelpers/AssertViewBody.swift b/Tests/ColorComponentsTests/XCHelpers/AssertViewBody.swift index 1c2f579f..90353104 100644 --- a/Tests/ColorComponentsTests/XCHelpers/AssertViewBody.swift +++ b/Tests/ColorComponentsTests/XCHelpers/AssertViewBody.swift @@ -2,6 +2,7 @@ import XCTest import SwiftUI +@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) @MainActor func XCTAssertBody( of view: V, @@ -9,12 +10,12 @@ func XCTAssertBody( _ message: @autoclosure () -> String = "", file: StaticString = #filePath, line: UInt = #line) { + let viewBody = view.body // Xcode as of version 16 erases all `some` return types to their `@_typeErasure` type (if any). // There is a build setting for projects (SWIFT_ENABLE_OPAQUE_TYPE_ERASURE=NO), but that's not possible for SPM packages. // However, we can "unpack" the any view for these builds. Worst case scenario: We don't check the view body. // Kudos to Joe Groff for digging up the build setting: https://f.duriansoftware.com/@joe/113170928606701687 #if Xcode && swift(>=6.0) - let viewBody = view.body XCTAssert(type(of: viewBody) == Expected.self || type(of: viewBody) == AnyView.self, "\(type(of: viewBody)) != \(Expected.self) || \(AnyView.self): \(message())", file: file, line: line) if let expectedTypeBody = viewBody as? Expected { @@ -24,8 +25,8 @@ func XCTAssertBody( XCTAssertEqual(actualView as? Expected, try body(), message(), file: file, line: line) } #else - XCTAssert(type(of: view.body) == Expected.self, "\(type(of: view.body)) != \(Expected.self): \(message())", file: file, line: line) - XCTAssertEqual(view.body as? Expected, try body(), message(), file: file, line: line) + XCTAssert(type(of: viewBody) == Expected.self, "\(type(of: viewBody)) != \(Expected.self): \(message())", file: file, line: line) + XCTAssertEqual(viewBody as? Expected, try body(), message(), file: file, line: line) #endif } #endif