Skip to content

Commit

Permalink
⭐️ Impl: UniqueIdentifierSynthesizing
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Sep 27, 2024
1 parent 51d94dc commit f5f4dd4
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ios/Temp/NSObject+UniqueIdentifierSynthesizing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// UIViewController+UniqueIdentifierSynthesizing.swift
// react-native-ios-modal
//
// Created by Dominic Go on 9/27/24.
//

import Foundation
import DGSwiftUtilities


extension NSObject: UniqueIdentifierSynthesizing {
// empty requirements
};
84 changes: 84 additions & 0 deletions ios/Temp/UniqueIdentifierSynthesizing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// UniqueIdentifierSynthesizing.swift
// react-native-ios-modal
//
// Created by Dominic Go on 9/27/24.
//

import Foundation
import DGSwiftUtilities

public protocol UniqueIdentifierSynthesizing: AnyObject {

var synthesizedIntID: UInt64 { get };

var synthesizedUUID: UUID { get };
};

// MARK: - UniqueIdentifierSynthesizing+Helpers
// --------------------------------------------

public extension UniqueIdentifierSynthesizing where Self: NSObject {

var synthesizedStringID: String {
"\(self.className)-\(self.synthesizedIntID)";
};

var synthesizedLongStringID: String {
"\(self.className)-\(self.synthesizedUUID)";
};

var synthesizedVeryLongStringID: String {
"\(self.className)-\(self.synthesizedIntID)-\(self.synthesizedUUID)";
};
};


public extension UniqueIdentifierSynthesizing where Self: AnyObject {

fileprivate var className: String {
String(describing: type(of: self));
};

var synthesizedStringID: String {
"\(self.className)-\(self.synthesizedIntID)";
};

var synthesizedLongStringID: String {
"\(self.className)-\(self.synthesizedUUID)";
};

var synthesizedVeryLongStringID: String {
"\(self.className)-\(self.synthesizedIntID)-\(self.synthesizedUUID)";
};
};

// MARK: - ObjectUniquelyIdentifiable+Default
// ------------------------------------------

fileprivate enum PropertyKeys: String {
case atomicCounter;
case synthesizedIntID;
case synthesizedUUID;
};

extension UniqueIdentifierSynthesizing where Self: ValueInjectable {

fileprivate var atomicCounter: AtomicCounter {
self.getInjectedValue(forKey: PropertyKeys.atomicCounter) {
.init();
};
};

public var synthesizedIntID: UInt64 {
self.getInjectedValue(forKey: PropertyKeys.synthesizedIntID) {
self.atomicCounter.incrementAndGet();
};
};

public var synthesizedUUID: UUID {
self.getInjectedValue(forKey: PropertyKeys.synthesizedUUID) {
.init();
};
};
};

0 comments on commit f5f4dd4

Please sign in to comment.