Skip to content

A Swift Property Wrapper to invalidate your view's layout or display based on property changes.

License

Notifications You must be signed in to change notification settings

b3ll/SetNeedsDisplay

Repository files navigation

SetNeedsDisplay

Tests

This package provides property wrappers that can be used on properties for any NSView or UIView to invalidate the layout or display whenever the value of said property is changed.

Note: This code contains some private Swift API stuff that powers @Published so there's a strong likelihood this will break in the future.

Usage

Annotate your property of a type that conforms to Equatable like so:

class MyView: UIView {

    // Anytime someCustomProperty is changed, `-setNeedsDisplay` will be called.
    @SetNeeds(.display) var someCustomProperty: CGFloat = 0.0


    // Anytime someOtherCustomProperty is changed, `-setNeedsLayout` will be called.
    @SetNeeds(.layout) var someOtherCustomProperty: CGFloat = 0.0


    // Anytime oneLastProperty is changed, `-setNeedsDisplay` and `-setNeedsLayout` will be called.
    @SetNeeds(.display, .layout) var oneLastProperty: CGFloat = 0.0

}

Installation

Requirements

  • iOS 13+, macOS 10.15+
  • Swift 5.0 or higher

Currently SetNeedsDisplay supports Swift Package Manager (or manually adding SetNeedsDisplay.swift to your project).

Swift Package Manager

Add the following to your Package.swift (or add it via Xcode's GUI):

.package(url: "https://github.com/b3ll/SetNeedsDisplay", from: "0.0.1")

License

SetNeedsDisplay is licensed under the BSD 2-clause license.

Thanks

Thanks to @harlanhaskins and @hollyborla for helping point me in the right direction and explain the complexity that this sort of solution entails.

More info here.

Contact Info

Feel free to follow me on twitter: @b3ll!

About

A Swift Property Wrapper to invalidate your view's layout or display based on property changes.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages