From b590a5c92f092dcdfc46c4c8bb51f1c74e94b508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20Do=C4=9Fan?= Date: Tue, 2 Apr 2024 15:07:05 +0300 Subject: [PATCH] Fix memory leak caused by NSLocalizedString --- .../Integrations/StringResource+Integrations.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sources/RswiftResources/Integrations/StringResource+Integrations.swift b/Sources/RswiftResources/Integrations/StringResource+Integrations.swift index 7a3f5659..418c37cc 100644 --- a/Sources/RswiftResources/Integrations/StringResource+Integrations.swift +++ b/Sources/RswiftResources/Integrations/StringResource+Integrations.swift @@ -12,12 +12,20 @@ extension String { switch source { case let .hosting(bundle): // With fallback to developmentValue - let format = NSLocalizedString(key.description, tableName: tableName, bundle: bundle, value: developmentValue ?? "", comment: "") + let format = if #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) { + String(localized: key, defaultValue: .init(developmentValue ?? ""), table: tableName, bundle: bundle, comment: "") + } else { + NSLocalizedString(key.description, tableName: tableName, bundle: bundle, value: developmentValue ?? "", comment: "") + } self = String(format: format, locale: overrideLocale ?? Locale.current, arguments: arguments) case let .selected(bundle, locale): // Don't use developmentValue with selected bundle/locale - let format = NSLocalizedString(key.description, tableName: tableName, bundle: bundle, value: "", comment: "") + let format = if #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) { + String(localized: key, defaultValue: .init(developmentValue ?? ""), table: tableName, bundle: bundle, comment: "") + } else { + NSLocalizedString(key.description, tableName: tableName, bundle: bundle, value: developmentValue ?? "", comment: "") + } self = String(format: format, locale: overrideLocale ?? locale, arguments: arguments) case .none: