From 7962c8e698dca65dbebf498f08b0cbab291678d7 Mon Sep 17 00:00:00 2001
From: Stefan Csomor <csomor@advancedconcepts.ch>
Date: Wed, 29 Oct 2025 14:21:22 +0100
Subject: [PATCH 28/48] using key value access to support older macOS SDKs

---
 src/osx/core/uilocale.mm | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/osx/core/uilocale.mm b/src/osx/core/uilocale.mm
index d3f7197c56..1ee08f189e 100644
--- a/src/osx/core/uilocale.mm
+++ b/src/osx/core/uilocale.mm
@@ -43,7 +43,7 @@
 {
     if (!gs_currentNSLocale)
     {
-        static wxCFRef<NSLocale*> stdCLocale([[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"] retain]);
+        static wxCFRef<NSLocale*> stdCLocale([[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]);
         gs_currentNSLocale = stdCLocale;
     }
     return gs_currentNSLocale;
@@ -105,7 +105,7 @@ explicit wxUILocaleImplCF(NSLocale* nsloc)
         bool isAvailable = false;
         NSString* availableLocaleId = NULL;
 
-        wxOBJC_FOR_LOOP( id nsLocId, [NSLocale availableLocaleIdentifiers] )
+        wxOBJC_FOR_LOOP( NSString* nsLocId, [NSLocale availableLocaleIdentifiers] )
         {
             // We can't simply compare the names here because the list returned
             // by NSLocale is incomplete and doesn't contain all synonyms, e.g.
@@ -157,11 +157,10 @@ explicit wxUILocaleImplCF(NSLocale* nsloc)
             return nullptr;
 
         wxCFStringRef cfName(locId.GetName());
-        auto nsloc = [NSLocale localeWithLocaleIdentifier: cfName.AsNSString()];
+        NSLocale* nsloc = [[NSLocale alloc] initWithLocaleIdentifier: cfName.AsNSString()];
         if ( !nsloc )
             return nullptr;
-
-        
+        [nsloc autorelease];
 
         return new wxUILocaleImplCF(nsloc);
     }
@@ -252,17 +251,17 @@ int CompareStrings(const wxString& lhs, const wxString& rhs,
             return wxString();
     }
 
-    NSString* str = nullptr;
+    NSString* str = nil;
     switch (name)
     {
         case wxLOCALE_NAME_LOCALE:
-            str = [convLocale localizedStringForLocaleIdentifier:[m_nsloc localeIdentifier]];
+            str = [convLocale displayNameForKey:NSLocaleIdentifier value:[m_nsloc objectForKey:NSLocaleIdentifier]];
             break;
         case wxLOCALE_NAME_LANGUAGE:
-            str = [convLocale localizedStringForLanguageCode:[m_nsloc languageCode]];
+            str = [convLocale displayNameForKey:NSLocaleLanguageCode value:[m_nsloc objectForKey:NSLocaleLanguageCode]];
             break;
         case wxLOCALE_NAME_COUNTRY:
-            str = [convLocale localizedStringForCountryCode:[m_nsloc countryCode]];
+            str = [convLocale displayNameForKey:NSLocaleCountryCode value:[m_nsloc objectForKey:NSLocaleCountryCode]];
             break;
     }
     return wxCFStringRef::AsString(str);
@@ -363,7 +362,7 @@ int CompareStrings(const wxString& lhs, const wxString& rhs,
 wxLayoutDirection
 wxUILocaleImplCF::GetLayoutDirection() const
 {
-    NSLocaleLanguageDirection layoutDirection = [NSLocale characterDirectionForLanguage:[m_nsloc languageCode]];
+    NSLocaleLanguageDirection layoutDirection = [NSLocale characterDirectionForLanguage:[m_nsloc objectForKey:NSLocaleLanguageCode]];
     if (layoutDirection == NSLocaleLanguageDirectionLeftToRight)
         return wxLayout_LeftToRight;
     else if (layoutDirection == NSLocaleLanguageDirectionRightToLeft)
@@ -380,14 +379,14 @@ int CompareStrings(const wxString& lhs, const wxString& rhs,
 wxString
 wxUILocaleImplCF::GetCurrencySymbol() const
 {
-    NSString* str = [m_nsloc currencySymbol];
+    NSString* str = [m_nsloc objectForKey:NSLocaleCurrencySymbol];
     return wxCFStringRef::AsString(str);
 }
 
 wxString
 wxUILocaleImplCF::GetCurrencyCode() const
 {
-    NSString* str = [m_nsloc currencyCode];
+    NSString* str = [m_nsloc objectForKey:NSLocaleCurrencyCode];
     return wxCFStringRef::AsString(str);
 }
 
@@ -491,7 +490,7 @@ int CompareStrings(const wxString& lhs, const wxString& rhs,
 {
     if ([m_nsloc respondsToSelector:@selector(usesMetricSystem)])
     {
-        BOOL isMetric = [m_nsloc usesMetricSystem];
+        BOOL isMetric = [(NSNumber*) [m_nsloc objectForKey:NSLocaleUsesMetricSystem] boolValue];
         return (isMetric) ? wxMeasurementSystem::Metric : wxMeasurementSystem::NonMetric;
     }
     return wxMeasurementSystem::Unknown;
@@ -505,7 +504,7 @@ int CompareStrings(const wxString& lhs, const wxString& rhs,
     // wouldn't be much better as we'd still need a hack for it in GetName()
     // because the locale names are always converted to lower case, while we
     // really want to return "C" rather than "c" as the name of this one.
-    return new wxUILocaleImplCF([NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]);
+    return new wxUILocaleImplCF([[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]);
 }
 
 /* static */
@@ -525,10 +524,11 @@ int CompareStrings(const wxString& lhs, const wxString& rhs,
 {
     wxVector<wxString> preferred;
     NSArray* preferredLangs = [NSLocale preferredLanguages];
-    NSUInteger count = preferredLangs.count;
-
-    for (NSUInteger j = 0; j < count; ++j)
-        preferred.push_back(wxCFStringRef::AsString(preferredLangs[j]));
+    wxOBJC_FOR_LOOP(NSString* preferredLang, preferredLangs)
+    {
+        preferred.push_back(wxCFStringRef::AsString(preferredLang));
+    }
+    wxOBJC_END_FOR_LOOP
 
     return preferred;
 }
-- 
2.24.3 (Apple Git-128)

