Files
swift-composable-architectu…/Sources/ComposableArchitecture/Internal/PresentationID.swift
Stephen Celis 7ac630fe4c Support swift-syntax from 600.0.0-latest (#3160)
* Support swift-syntax from 600.0.0-latest

The Xcode 16 beta generates macro projects using these swift-syntax
snapshots. Luckily things seem to be backwards compatible, so we can
expand our supported range.

* wip
2024-06-12 16:02:02 -07:00

38 lines
915 B
Swift

@_spi(Reflection) import CasePaths
extension PresentationState {
var id: PresentationID? {
self.wrappedValue.map(PresentationID.init(base:))
}
}
struct PresentationID: Hashable, Identifiable {
private let identifier: AnyHashable?
private let tag: UInt32?
private let type: Any.Type
init<Base>(base: Base) {
self.tag = EnumMetadata(Base.self)?.tag(of: base)
if let id = _identifiableID(base) ?? EnumMetadata.project(base).flatMap(_identifiableID) {
self.identifier = id
} else {
self.identifier = nil
}
self.type = Base.self
}
var id: Self { self }
static func == (lhs: Self, rhs: Self) -> Bool {
lhs.identifier == rhs.identifier
&& lhs.tag == rhs.tag
&& lhs.type == rhs.type
}
func hash(into hasher: inout Hasher) {
hasher.combine(self.identifier)
hasher.combine(self.tag)
hasher.combine(ObjectIdentifier(self.type))
}
}