CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.
TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2015 |
SPMSupports SPM | ✗ |
Maintained by Zaid.
by ark. tweet @arkverse for any feature requests. Feedback is greatly appreciated!
A Swift closure library for UIKit that makes events significantly easier and cleaner. Currently supports closures on UIControl
events and UIGestureRecognizers
(all subclasses). We will be adding more closure support as we go along. Memory managed and written completely in Swift.
All the UIControlEvents
are supported, and multiple closures can be added to the same event.
Quick example:
button.on(.TouchUpInside, (sender: AnyObject) -> () {
let button = sender as! UIButton
button.setTitle("Pressed", forControlState:.Normal)
})
Be sure to check out our SwiftRecord library too!
Visit ark for a more beginner friendly guide to UIClosures
If you love UIClosures, tweet it!
Drag and drop either Classes/UIClosures.swift
or UIClosures.framework
into your project
import UIClosures
into your file (if needed)call on
on your UIControl or one of the convenience methods like onTouchUpInside
// Make sure you set your capture list to break your class-closure strong reference loop
on(.TouchUpInside, listener: { [unowned self] (sender) -> () in
self.title = "New ViewController Title!"
let button = sender as! UIButton
button.titleLabel?.font = UIFont.systemFont
})
// Can add another closure to the same event, convenience method used here
button.onTouchUpInside() {[weak button = button] (sender) -> () in
button.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)
})
Use any of the subclasses you want. You must use the closure initializer and not the target: action:
initializer:
let tap = UITapGestureRecognizer() { (gesture: UITapGestureRecognizer) -> () in
println("got a tap")
}
tap.onGesture() { (gesture: UITapGestureRecognizer) -> () in
println("got this tap again")
}
Will call all of your closures
Again, remember your capture list if referring to any variables
UIClosures is available under the MIT license. See the LICENSE file for more information.
Check out ark for more about us and check out our other Swift libraries