From 6ad239fb39f607a8b1d1dfa1e9bc8744714e93c1 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 25 Apr 2025 09:30:25 -0700 Subject: [PATCH] =?UTF-8?q?Add=20sharingServicesForItems=5FnoDeprecationWa?= =?UTF-8?q?rning=20to=20silence=20deprecation=20that=20we=E2=80=99re=20acc?= =?UTF-8?q?epting.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Timeline/NSSharingService+Extension.h | 23 +++++++++++++++++++ .../Timeline/NSSharingService+Extension.m | 22 ++++++++++++++++++ ...melineViewController+ContextualMenus.swift | 2 +- Mac/NetNewsWire-Bridging-Header.h | 1 + 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Mac/MainWindow/Timeline/NSSharingService+Extension.h create mode 100644 Mac/MainWindow/Timeline/NSSharingService+Extension.m diff --git a/Mac/MainWindow/Timeline/NSSharingService+Extension.h b/Mac/MainWindow/Timeline/NSSharingService+Extension.h new file mode 100644 index 000000000..389a58161 --- /dev/null +++ b/Mac/MainWindow/Timeline/NSSharingService+Extension.h @@ -0,0 +1,23 @@ +// +// NSObject+NSSharingService_RSCore.h +// RSCore +// +// Created by Brent Simmons on 11/3/24. +// + +@import AppKit; + +@interface NSSharingService (NoDeprecationWarning) + +// The only way to create custom UI — a Share menu, for instance — +// is to use the unfortunately deprecated +// +[NSSharingService sharingServicesForItems:]. +// This cover method allows us to not generate a warning. +// +// We know it’s deprecated, and we don’t want to be bugged +// about it every time we build. (If anyone from Apple +// is reading this — a replacement would be very welcome!) + ++ (NSArray *)sharingServicesForItems_noDeprecationWarning:(NSArray *)items; + +@end diff --git a/Mac/MainWindow/Timeline/NSSharingService+Extension.m b/Mac/MainWindow/Timeline/NSSharingService+Extension.m new file mode 100644 index 000000000..cf2e71e26 --- /dev/null +++ b/Mac/MainWindow/Timeline/NSSharingService+Extension.m @@ -0,0 +1,22 @@ +// +// NSSharingService+Extension.m +// RSCore +// +// Created by Brent Simmons on 11/3/24. +// + +#import "NSSharingService+Extension.h" + +@implementation NSSharingService (NoDeprecationWarning) + ++ (NSArray *)sharingServicesForItems_noDeprecationWarning:(NSArray *)items { + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + + return [NSSharingService sharingServicesForItems:items]; + +#pragma clang diagnostic pop +} + +@end diff --git a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift index dd83afdcb..1cc5d6e3e 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift @@ -200,7 +200,7 @@ private extension TimelineViewController { let sortedArticles = articles.sortedByDate(.orderedAscending) let items = sortedArticles.map { ArticlePasteboardWriter(article: $0) } - let standardServices = NSSharingService.sharingServices(forItems: items) + let standardServices = NSSharingService.sharingServices(forItems_noDeprecationWarning: items) as? [NSSharingService] ?? [NSSharingService]() let customServices = SharingServicePickerDelegate.customSharingServices(for: items) let services = standardServices + customServices if services.isEmpty { diff --git a/Mac/NetNewsWire-Bridging-Header.h b/Mac/NetNewsWire-Bridging-Header.h index 3f547bcf1..01bbec4e2 100644 --- a/Mac/NetNewsWire-Bridging-Header.h +++ b/Mac/NetNewsWire-Bridging-Header.h @@ -7,3 +7,4 @@ // #import "WKPreferencesPrivate.h" +#import "NSSharingService+Extension.h"