Last active
February 1, 2021 12:50
-
-
Save b3ll/b317d463fa3f9ebaee5d41c6a8dcfc32 to your computer and use it in GitHub Desktop.
Revisions
-
Adam Bell revised this gist
Dec 22, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ @propertyWrapper public final class LayoutInvalidating<Value> where Value: Equatable { public static subscript<EnclosingSelf>( -
Adam Bell revised this gist
Dec 22, 2020 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,6 @@ public final class LayoutInvalidating<Value> where Value: Equatable { observed[keyPath: storageKeyPath].stored = newValue if newValue != oldValue { observed.setNeedsLayout() } } -
Adam Bell created this gist
Dec 22, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ propertyWrapper public final class LayoutInvalidating<Value> where Value: Equatable { public static subscript<EnclosingSelf>( _enclosingInstance observed: EnclosingSelf, wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>, storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, LayoutInvalidating> ) -> Value where EnclosingSelf: UIView { get { return observed[keyPath: storageKeyPath].stored } set { let oldValue = observed[keyPath: storageKeyPath].stored observed[keyPath: storageKeyPath].stored = newValue if newValue != oldValue { // TODO: call wrapper instance with enclosing self observed.setNeedsLayout() } } } public var wrappedValue: Value { get { fatalError("called wrappedValue getter") } set { fatalError("called wrappedValue setter") } } public init(wrappedValue: Value) { self.stored = wrappedValue } // MARK: - Private private var stored: Value } // Test for Playgrounds public class SomeView: UIView { @LayoutInvalidating public var volume: CGFloat = 0.0 } let a = SomeView(frame: .zero) a.volume = 20.0