From ef6b4e74e26672d3cc880546637f5554fe027522 Mon Sep 17 00:00:00 2001 From: Peter Curry Date: Fri, 10 Apr 2026 11:36:08 +1200 Subject: [PATCH 1/2] Add InteropTypeNameAttribute. Change NSObject.GetInteropTypeName to ceck for InteropTypeNameAttribute instead of looking for static InteropTypeName proprety. --- .../Runtime/InteropTypeNameAttribute.cs | 19 +++++++++++++++++++ .../Runtime/InteropTypeNameAttribute.cs.meta | 3 +++ .../Assets/Apple.Core/Runtime/NSObject.cs | 3 +-- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/InteropTypeNameAttribute.cs create mode 100644 plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/InteropTypeNameAttribute.cs.meta diff --git a/plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/InteropTypeNameAttribute.cs b/plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/InteropTypeNameAttribute.cs new file mode 100644 index 00000000..3c61caae --- /dev/null +++ b/plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/InteropTypeNameAttribute.cs @@ -0,0 +1,19 @@ +using System; + +namespace Apple.Core +{ + /// + /// Attribute for manually specifying a class's corresponding Objective-C type name. This is required for classes + /// that do not share their C# type name with their Objective-C counterpart, such as nested classes. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public class InteropTypeNameAttribute : Attribute + { + public string TypeName { get; private set; } + + public InteropTypeNameAttribute(string customTypeName) + { + TypeName = customTypeName; + } + } +} diff --git a/plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/InteropTypeNameAttribute.cs.meta b/plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/InteropTypeNameAttribute.cs.meta new file mode 100644 index 00000000..218967ff --- /dev/null +++ b/plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/InteropTypeNameAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6c3c61f3764d4688a279325a72606e82 +timeCreated: 1775773530 \ No newline at end of file diff --git a/plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/NSObject.cs b/plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/NSObject.cs index 5b833e15..82e12f8b 100644 --- a/plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/NSObject.cs +++ b/plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Runtime/NSObject.cs @@ -38,8 +38,7 @@ protected static string GetInteropTypeName(Type type) var typeName = type.Name; // Special case for types that provide a custom interop type name. - if (type.GetProperty("InteropTypeName", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) - ?.GetValue(null) is string customTypeName) + if(type.GetCustomAttribute()?.TypeName is string customTypeName) { typeName = customTypeName; } From c500932f0d906fd168d18c24c39b0bb9711d6537 Mon Sep 17 00:00:00 2001 From: Peter Curry Date: Fri, 10 Apr 2026 13:13:38 +1200 Subject: [PATCH 2/2] Replace GKLeaderboard.Entry InteropTypeName property with InteropTypeNameAttribute. --- .../Assets/Apple.GameKit/Source/Leaderboards/GKLeaderboard.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plug-ins/Apple.GameKit/Apple.GameKit_Unity/Assets/Apple.GameKit/Source/Leaderboards/GKLeaderboard.cs b/plug-ins/Apple.GameKit/Apple.GameKit_Unity/Assets/Apple.GameKit/Source/Leaderboards/GKLeaderboard.cs index b5fe5b77..24a5afcd 100644 --- a/plug-ins/Apple.GameKit/Apple.GameKit_Unity/Assets/Apple.GameKit/Source/Leaderboards/GKLeaderboard.cs +++ b/plug-ins/Apple.GameKit/Apple.GameKit_Unity/Assets/Apple.GameKit/Source/Leaderboards/GKLeaderboard.cs @@ -58,14 +58,12 @@ public enum TimeScope : long /// /// Information about a single score by a player on a leaderboard. /// + [InteropTypeName("GKLeaderboardEntry")] [Introduced(iOS: "14.0", macOS: "11.0", tvOS: "14.0", visionOS: "1.0")] public class Entry : NSObject { internal Entry(IntPtr pointer) : base(pointer) {} - // This allows interop to work with the Objective-C type which has a different name: GKLeaderboardEntry. - internal static string InteropTypeName => "GKLeaderboardEntry"; - /// /// An integer value that your game uses. ///