-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭐️ Impl:
UniqueIdentifierSynthesizing
- Loading branch information
1 parent
51d94dc
commit f5f4dd4
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
}; | ||
}; |