NSView.Invalidating
A property wrapper that notifies the system that a property value change has invalidated an aspect of the containing view.
Declaration
@propertyWrapper struct Invalidating<Value, InvalidationType> where Value : Equatable, InvalidationType : NSViewInvalidatingOverview
Use this wrapper when a change in the property value invalidates the display, layout, configuration, constraints, or intrinsic sizing of a view. This wrapper performs any actions necessary to notify the system that your view is invalid and requires an update. The actions depend on the invalidation types you specify. For more information on available invalidation types, see NSViewInvalidating.
The following example uses the NSView.Invalidating wrapper with the display type on the property fillColor and the display and layout type on the property badgePosition.
class MyView: NSView {
@Invalidating(.display) var fillColor: NSColor
@Invalidating(.display, .layout) var badgePosition: NSRectEdge
}When you change the fill color, the property wrapper sets needsDisplay to true, causing the system to redraw the view. When you change the badge position, the property wrapper also sets needsLayout to true, causing the system to update the view’s subviews before it redraws.
Functions such as setNeedsDisplay and setNeedsLayout perform changes on the next update cycle. You can make changes to multiple properties and views before any of those views update. Consolidating the updates to one update cycle is usually better for performance.
Topics
Creating an Invalidating Property Wrapper
init(wrappedValue:_:)init(wrappedValue:_:_:)init(wrappedValue:_:_:_:)init(wrappedValue:_:_:_:_:)init(wrappedValue:_:_:_:_:_:)init(wrappedValue:_:_:_:_:_:_:)init(wrappedValue:_:_:_:_:_:_:_:)init(wrappedValue:_:_:_:_:_:_:_:_:)init(wrappedValue:_:_:_:_:_:_:_:_:_:)init(wrappedValue:_:_:_:_:_:_:_:_:_:_:)