From 8ea197299b34ebd7ce07cecb748d3c93fe0f38fb Mon Sep 17 00:00:00 2001 From: Gnohz Gniy <0x00eeee@gmail.com> Date: Mon, 31 Jul 2023 16:41:08 +0800 Subject: [PATCH] allowsInlinePredictions is now available (#248) --- .../WKWebViewConfiguration+Extension.swift | 19 ++++++++++++++----- MarkEditMacTests/RuntimeTests.swift | 9 +++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/MarkEditKit/Sources/Extensions/WKWebViewConfiguration+Extension.swift b/MarkEditKit/Sources/Extensions/WKWebViewConfiguration+Extension.swift index 287ae0ca..57d78cd2 100644 --- a/MarkEditKit/Sources/Extensions/WKWebViewConfiguration+Extension.swift +++ b/MarkEditKit/Sources/Extensions/WKWebViewConfiguration+Extension.swift @@ -32,16 +32,25 @@ public extension WKWebViewConfiguration { return false } - // [macOS 14] WebKit hasn't yet exposed this as public, even it's documented - return responds(to: sel_getUid("setAllowsInlinePredictions:")) + #if compiler(>=5.9) + return true + #else + return responds(to: sel_getUid("setAllowsInlinePredictions:")) + #endif } - func setAllowsInlinePredictions(_ allowsInlinePredictions: Bool) { + func setAllowsInlinePredictions(_ newValue: Bool) { guard supportsInlinePredictions else { return } - // [macOS 14] WebKit hasn't yet exposed this as public, even it's documented - setValue(allowsInlinePredictions, forKey: "allowsInlinePredictions") + #if compiler(>=5.9) + if #available(macOS 14.0, *) { + allowsInlinePredictions = newValue + return + } + #endif + + setValue(newValue, forKey: "allowsInlinePredictions") } } diff --git a/MarkEditMacTests/RuntimeTests.swift b/MarkEditMacTests/RuntimeTests.swift index c3a593ad..e72d01fd 100644 --- a/MarkEditMacTests/RuntimeTests.swift +++ b/MarkEditMacTests/RuntimeTests.swift @@ -15,10 +15,11 @@ final class RuntimeTests: XCTestCase { return } - // [macOS 14] Remove after WebKit exposes this as public - let configuration = WKWebViewConfiguration() - configuration.setValue(true, forKey: "allowsInlinePredictions") - testExistenceOfSelector(object: configuration, selector: "setAllowsInlinePredictions:") + #if compiler(<5.9) + let configuration = WKWebViewConfiguration() + configuration.setValue(true, forKey: "allowsInlinePredictions") + testExistenceOfSelector(object: configuration, selector: "setAllowsInlinePredictions:") + #endif } func testExistenceOfDrawsBackground() {