Skip to content

Utility wrapper that delays property-setting operations until the wrapped value is set.

Notifications You must be signed in to change notification settings

jarroolabs/DelayedPropertySetter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DelayedPropertySetter

Utility wrapper that delays property-setting operations until the wrapped value is set.

Useful for situations where a value is initialized at a later time (e.g. viewDidLoad, @IBOutlet), while its properties can (or should) be set a different (possibly earlier) time, controlled by some animation or user action (e.g. changing a controller's additionalSafeAreaInsets before the controller has been lazily initialized).

Example usage

let childController = DelayedPropertySetter<UIViewController>()

func set(newChildController: MenuContentController) {
    self.childController.set(to: newChildController)
    addChild(newChildController)
    // ...
}
 
func update(accessoryViewHeight: CGFloat, animated: Bool) {
    childController.setProperty(
        \.additionalSafeAreaInsets,
        to: UIEdgeInsets(top: 0, left: 0, bottom: accessoryViewHeight, right: 0)
    )
    // ...
}

The child controller's additionalSafeAreaInsets would still be set, even though update(accessoryViewHeight:animated) might get called before the childController variable is set.

About

Utility wrapper that delays property-setting operations until the wrapped value is set.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages