From 7f7b106dc7f9f53d835f671a05d76c451d03bfb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Tue, 3 Dec 2024 15:09:27 +0100 Subject: [PATCH] Fix deprecation warnings about UTType API --- Sources/SwiftDocC/Servers/FileServer.swift | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Sources/SwiftDocC/Servers/FileServer.swift b/Sources/SwiftDocC/Servers/FileServer.swift index 90e79fb6ab..c5c714918a 100644 --- a/Sources/SwiftDocC/Servers/FileServer.swift +++ b/Sources/SwiftDocC/Servers/FileServer.swift @@ -13,6 +13,9 @@ import SymbolKit #if canImport(FoundationNetworking) import FoundationNetworking #endif +#if canImport(UniformTypeIdentifiers) +import UniformTypeIdentifiers +#endif #if os(Windows) import WinSDK #endif @@ -116,15 +119,7 @@ public class FileServer { #if os(macOS) - let unmanagedFileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, ext as CFString, nil) - guard let fileUTI = unmanagedFileUTI?.takeRetainedValue() else { - return defaultMimeType - } - guard let mimeType = UTTypeCopyPreferredTagWithClass (fileUTI, kUTTagClassMIMEType)?.takeRetainedValue() else { - return defaultMimeType - } - - return (mimeType as NSString) as String + return UTType(filenameExtension: ext)?.preferredMIMEType ?? defaultMimeType #elseif os(Windows)