Latest 0.0.4
Homepage https://github.com/arkverse/UIClosures
License MIT
Platforms ios 8.0, requires ARC
Authors

UIClosures CocoaPod Carthage compatible MIT license [Issues]( https://github.com/arkverse/UIClosures/issues)

by ark. tweet @arkverse for any feature requests. Feedback is greatly appreciated!

About

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!
<img src="
http://jpillora.com/github-twitter-button/img/tweet.png"
alt="tweet button" title="UIClosures">

Installation

via CocoaPods

  1. Edit your Podfile to use frameworks and add UIClosures:

    platform :ios, '8.0'
    use_frameworks!
    
    pod 'UIClosures', '~> 0.0.2'
  2. run pod install

via Carthage

  1. Just add UIClosures to your Cartfile:

    github "arkverse/UIClosures" >= 0.0.2
  2. and run carthage update

Manual Installation

Drag and drop either Classes/UIClosures.swift or UIClosures.framework into your project

Usage

UIControls

  1. import UIClosures into your file (if needed)
  2. 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)
    })
  3. Note that you most likely need your capture list for each closure

UIGestureRecognizer

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

Roadmap

  • add more closures
  • testing

License

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

ga tracker

Latest podspec

{
    "name": "UIClosures",
    "version": "0.0.4",
    "summary": "Swift closure library for UIKit",
    "description": "Closure based UI events. Supports UIControls and UIGestureRecognizers. Written purely in Swift and memory managed. Cheers",
    "homepage": "https://github.com/arkverse/UIClosures",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Zaid Daghestani": "[email protected]"
    },
    "social_media_url": "http://twitter.com/arkverse",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/arkverse/UIClosures.git",
        "tag": "v0.0.4"
    },
    "source_files": [
        "Classes",
        "Classes/**/*.{swift}"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This