🔮Mirror
💾 程式:paiza.io
HasMirrors - use Mirror to inspect types.
CaseReflectable - inspect enum case.
NonNominalTypeWrapper - help inspect non-nominal types.
enum case pattern - use Mirror to pattern match an enum case.
// --------------------
// Type aliases
// --------------------
// An element of the reflected instance’s structure
// label: nil | stored property name | enum case name.
typealias Mirror.Child = (label: String?, value: Any)
// The type used to represent substructure.
typealias Mirror.Children = AnyCollection<Mirror.Child>
// -------------
// Types
// -------------
// Playgrounds and debugger will use this as suggestion to show subject.
enum Mirror.DisplayStyle {
case `class`
case collection
case dictionary
case `enum`
case optional
case set
case `struct`
case tuple
}Swift ⟩
String ⟩
.init(reflecting:) - String(reflecting: subject) CustomDebugStringConvertible → CustomStringConvertible → TextOutputStreamable → Swift standard library
.init(describing:) - String(describing: subject) TextOutputStreamable → CustomStringConvertible → CustomDebugStringConvertible → Swift standard library
Swift.org ⟩ How Mirror Works - how Mirror works under the hood.
filter cases - use Mirror to do pattern matching.
HasMirrors - helper protocol to mirror subjects.
CaseReflectable - use Mirror to get enum case name/associated values.
NonNominalTypeWrapper - wrap non-nominal types to conform to Loggable.
關鍵字:meta programming, reflection
Last updated
Was this helpful?