UILifeCycleClosure 1.0.0

UILifeCycleClosure 1.0.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Oct 2015

Maintained by ukitaka.



 
Depends on:
ISMethodSwizzling>= 0
Aspects>= 0
 

  • By
  • ukitaka

Usage

afterViewDidLoad / afterAwakeFromNib

IBOutlets are initialized during view loading process and they are not accessible at the point you are trying to reach them.

In UIViewController, afterViewDidLoad guarantees that block will invoke after view is loaded. If isViewLoaded is true, invoke a block immediately.

@IBOutlet weak var label: UILabel!

func configLabel(text: String) {
    afterViewDidLoad {
        self.label.text = text
    }
}

afterViewDidLoadSafety is available to perform more safely.

guard let _ = try? afterViewDidLoadSafety({ self.label.text = text }) else {
    preconditionFailure()
}

Similarly, afterAwakeFromNib is available in a UIView.

func configLabel(text: String) {
    afterAwakeFromNib {
        self.label.text = text
    }
}

afterViewDidAppear

afterViewDidLoad guarantees that block will invoke after viewDidAppear:. For example, if you call presentViewController before viewDidAppear:, then the warning "Presenting view controllers on detached view controllers is discouraged…" will be displayed in Xcode.

afterViewDidAppear can be used as follows

afterViewDidAppear {
    self.presentViewController(vc, animated: true, completion: nil)
}

Requirements

  • iOS8.0+
  • Xcode7.0+

Installation

UILifeCycleClosure is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "UILifeCycleClosure"

Author

ukitaka, [email protected]

License

UILifeCycleClosure is available under the MIT license. See the LICENSE file for more info.