From 397a4f70769eec76d1b049e96d519dea0f8f8666 Mon Sep 17 00:00:00 2001 From: Dominic Go Date: Fri, 27 Sep 2024 18:05:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20Fix:=20`UniqueIdentifierSynthesi?= =?UTF-8?q?zing.=20synthesizedStringID`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Temp/NSObject+Helpers.swift | 22 ++++++++++++++++++ ios/Temp/UniqueIdentifierSynthesizing.swift | 25 +++++++++++++++------ 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 ios/Temp/NSObject+Helpers.swift diff --git a/ios/Temp/NSObject+Helpers.swift b/ios/Temp/NSObject+Helpers.swift new file mode 100644 index 00000000..fc1da37e --- /dev/null +++ b/ios/Temp/NSObject+Helpers.swift @@ -0,0 +1,22 @@ +// +// NSObject+Helpers.swift +// react-native-ios-modal +// +// Created by Dominic Go on 9/27/24. +// + +import Foundation + + +public extension NSObject { + var classNameTruncated: String { + let fullClassName = self.className; + let classNameComponents = fullClassName.components(separatedBy: "."); + + guard let className = classNameComponents.last else { + return fullClassName; + }; + + return className; + } +}; diff --git a/ios/Temp/UniqueIdentifierSynthesizing.swift b/ios/Temp/UniqueIdentifierSynthesizing.swift index 5e884d1e..103ac891 100644 --- a/ios/Temp/UniqueIdentifierSynthesizing.swift +++ b/ios/Temp/UniqueIdentifierSynthesizing.swift @@ -21,15 +21,15 @@ public protocol UniqueIdentifierSynthesizing: AnyObject { public extension UniqueIdentifierSynthesizing where Self: NSObject { var synthesizedStringID: String { - "\(self.className)-\(self.synthesizedIntID)"; + "\(self.classNameTruncated)-\(self.synthesizedIntID)"; }; var synthesizedLongStringID: String { - "\(self.className)-\(self.synthesizedUUID)"; + "\(self.classNameTruncated)-\(self.synthesizedUUID)"; }; var synthesizedVeryLongStringID: String { - "\(self.className)-\(self.synthesizedIntID)-\(self.synthesizedUUID)"; + "\(self.classNameTruncated)-\(self.synthesizedIntID)-\(self.synthesizedUUID)"; }; }; @@ -37,19 +37,30 @@ public extension UniqueIdentifierSynthesizing where Self: NSObject { public extension UniqueIdentifierSynthesizing where Self: AnyObject { fileprivate var className: String { - String(describing: type(of: self)); + return String(describing: type(of: self)); + }; + + fileprivate var classNameTruncated: String { + let fullClassName = self.className; + let classNameComponents = fullClassName.components(separatedBy: "."); + + guard let className = classNameComponents.last else { + return fullClassName; + }; + + return className; }; var synthesizedStringID: String { - "\(self.className)-\(self.synthesizedIntID)"; + "\(self.classNameTruncated)-\(self.synthesizedIntID)"; }; var synthesizedLongStringID: String { - "\(self.className)-\(self.synthesizedUUID)"; + "\(self.classNameTruncated)-\(self.synthesizedUUID)"; }; var synthesizedVeryLongStringID: String { - "\(self.className)-\(self.synthesizedIntID)-\(self.synthesizedUUID)"; + "\(self.classNameTruncated)-\(self.synthesizedIntID)-\(self.synthesizedUUID)"; }; };