From fe0036eb7e01e8cf04699e154b32bc935a8399b4 Mon Sep 17 00:00:00 2001 From: cuong mac mini m2 Date: Mon, 8 Jun 2026 16:57:23 +0700 Subject: [PATCH] Migrate MIME-type lookup to UTType (UniformTypeIdentifiers) Replace the deprecated CoreServices UTI calls (UTTypeCreatePreferredIdentifierForTag / UTTypeCopyPreferredTagWithClass) in GCDWebServerGetMimeTypeForExtension with the modern [UTType typeWithFilenameExtension:].preferredMIMEType, removing the -Wdeprecated-declarations pragma. Behavior is unchanged: known extensions map to the same MIME type, unknown ones fall back to the default. The UniformTypeIdentifiers framework (macOS 11+ / iOS 14+ / tvOS 14+, within the project's deployment targets) is now linked in all three build systems: Xcode (OTHER_LDFLAGS), CocoaPods (Core subspec frameworks), and SwiftPM (linkedFramework). Verified: Run-Tests.sh, swift build, and pod lib lint all pass. Co-Authored-By: Claude Opus 4.8 (1M context) --- CLAUDE.md | 2 +- GCDWebServer.podspec | 1 + GCDWebServer.xcodeproj/project.pbxproj | 2 ++ GCDWebServer/Core/GCDWebServerFunctions.m | 13 ++----------- Package.swift | 1 + 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 5abc6ad..fde91de 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -44,7 +44,7 @@ This script was originally written for Xcode 11.3 and was updated for current Xc - The `webUploader` fixture test is **commented out**: this fork customized `GCDWebUploader` (delete/move/create disabled in commit `ef4b622`), so the recorded `Tests/WebUploader` fixtures no longer match. Re-record them or re-enable the line if those features are restored. - The **tvOS build step is commented out** because it requires the tvOS Simulator runtime to be installed (`xcodebuild -downloadPlatform tvOS`); without it the storyboard compile fails with "tvOS … Platform Not Installed". Re-enable once the runtime is present. -Two project/source adjustments were also needed for the suite to build under current Xcode: the `Tests (Mac)` target sets `GENERATE_INFOPLIST_FILE = YES`, and the deprecated CoreServices UTI calls in `GCDWebServerFunctions.m` are wrapped in a `-Wdeprecated-declarations` pragma (the project builds Release with `-Werror`). +A project adjustment was also needed for the suite to build under current Xcode: the `Tests (Mac)` target sets `GENERATE_INFOPLIST_FILE = YES`. MIME-type lookup in `GCDWebServerFunctions.m` uses the modern `UTType` API (UniformTypeIdentifiers), so that framework is linked in all three build systems (Xcode `OTHER_LDFLAGS`, the podspec Core subspec, and `Package.swift`). ### How the fixture-replay tests work diff --git a/GCDWebServer.podspec b/GCDWebServer.podspec index 104ac17..c5946cc 100644 --- a/GCDWebServer.podspec +++ b/GCDWebServer.podspec @@ -16,6 +16,7 @@ Pod::Spec.new do |s| s.subspec 'Core' do |cs| cs.source_files = 'GCDWebServer/**/*.{h,m}' cs.private_header_files = "GCDWebServer/Core/GCDWebServerPrivate.h" + cs.frameworks = 'UniformTypeIdentifiers' cs.ios.library = 'z' cs.ios.frameworks = 'CoreServices', 'CFNetwork' cs.tvos.library = 'z' diff --git a/GCDWebServer.xcodeproj/project.pbxproj b/GCDWebServer.xcodeproj/project.pbxproj index 94fc650..7e59451 100644 --- a/GCDWebServer.xcodeproj/project.pbxproj +++ b/GCDWebServer.xcodeproj/project.pbxproj @@ -1169,6 +1169,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; BUNDLE_VERSION_STRING = 3.5.4; + OTHER_LDFLAGS = "-framework UniformTypeIdentifiers"; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; @@ -1239,6 +1240,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; BUNDLE_VERSION_STRING = 3.5.4; + OTHER_LDFLAGS = "-framework UniformTypeIdentifiers"; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; diff --git a/GCDWebServer/Core/GCDWebServerFunctions.m b/GCDWebServer/Core/GCDWebServerFunctions.m index c374e29..4794425 100644 --- a/GCDWebServer/Core/GCDWebServerFunctions.m +++ b/GCDWebServer/Core/GCDWebServerFunctions.m @@ -35,6 +35,7 @@ #else #import #endif +#import #import #import @@ -176,17 +177,7 @@ NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension, NSDictionary< mimeType = [builtInOverrides objectForKey:extension]; } if (mimeType == nil) { - // These CoreServices UTI functions are deprecated since macOS 12 / iOS 15 in favor of the - // UniformTypeIdentifiers UTType class, but they still work and avoid pulling in a new framework - // dependency across the Xcode/CocoaPods/SPM builds. Silence the deprecation under -Werror. -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL); - if (uti) { - mimeType = CFBridgingRelease(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)); - CFRelease(uti); - } -#pragma clang diagnostic pop + mimeType = [UTType typeWithFilenameExtension:extension].preferredMIMEType; } } return mimeType ? mimeType : kGCDWebServerDefaultMimeType; diff --git a/Package.swift b/Package.swift index 546ac19..a851daa 100644 --- a/Package.swift +++ b/Package.swift @@ -27,6 +27,7 @@ let package = Package( ], linkerSettings: [ .linkedLibrary("z"), + .linkedFramework("UniformTypeIdentifiers"), .linkedFramework("CoreServices", .when(platforms: [.iOS, .tvOS])), .linkedFramework("CFNetwork", .when(platforms: [.iOS, .tvOS])), .linkedFramework("SystemConfiguration", .when(platforms: [.macOS])),