Latest 1.0.0
Homepage https://github.com/ukitaka/UILifeCycleClosure
License MIT
Platforms ios 8.0, requires ARC
Dependencies ISMethodSwizzling, Aspects
Frameworks UIKit
Authors

Build Status
Version
License
Platform
Swift 2 compatible

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.

Latest podspec

{
    "name": "UILifeCycleClosure",
    "version": "1.0.0",
    "summary": "Provide a util method for UIView, UIViewController life cycle.",
    "homepage": "https://github.com/ukitaka/UILifeCycleClosure",
    "license": "MIT",
    "authors": {
        "ukitaka": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ukitaka/UILifeCycleClosure.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "UILifeCycleClosure": [
            "Pod/Assets/*.png"
        ]
    },
    "frameworks": "UIKit",
    "dependencies": {
        "ISMethodSwizzling": [],
        "Aspects": []
    }
}

Pin It on Pinterest

Share This