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
import SwiftUI | |
import Combine | |
/// The idea is to use State to create a storage object which will be | |
/// cached and restored by the framework. Then during the update phase we | |
/// re-inject the object into a nested ObservableObject and subscribe to the | |
/// ObjectType’s objectWillChange to forward to the _MessageForwarder’s | |
/// objectWillChange which is already subscribed by the framework as it’s an | |
/// inner dynamic property of our custom PW which is also a dynamic property. | |
@propertyWrapper |
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
struct User: Equatable { | |
var firstName: String | |
var lastName: String | |
} | |
@main | |
struct MyApp: App { | |
@State var value = User(firstName: "", lastName: "") | |
@State var showEdit = false | |
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
/// Classes whose initializers actually create derived classes | |
protocol FactoryInitializable { | |
/// The type of the least-derived class declared to be FactoryInitializable. | |
/// | |
/// - Warning: Do not define this in your FactoryInitializable type! | |
associatedtype FactoryBase: AnyObject, FactoryInitializable = Self | |
// This associatedtype is a trick that captures `Self` at the point where | |
// `FactoryInitializable` enters a class hierarchy; in other contexts, `Self` | |
// refers to the most-derived type. | |
} |
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
/// - returns: `true` when dynamic type is `Equatable` and `==` returns `true`, otherwise `false`. | |
func areEquatablyEqual(_ lhs: Any, _ rhs: Any) -> Bool { | |
func receiveLHS<LHS>(_ typedLHS: LHS) -> Bool { | |
guard | |
let rhsAsLHS = rhs as? LHS | |
else { return false } | |
return areEquatablyEqual(typedLHS, rhsAsLHS) | |
} | |
return _openExistential(lhs, do: receiveLHS) | |
} |