Giter VIP home page Giter VIP logo

actionkit's Introduction

Banner Version Carthage License Platform Swift

ActionKit

ActionKit is a light-weight, easy to use framework that wraps the target-action design paradigm into a less verbose, cleaner format. It shortens target-action method calls by removing the target and replacing the selector with a closure.

Example of target-action without ActionKit

button.addTarget(self, action: #selector(MyViewController.buttonWasTapped(_:)), forControlEvents: .TouchUpInside)

and somewhere else...

func buttonWasTapped(sender: Any) {
  if let button = sender as? UIButton {
    button.setTitle("Button was tapped!", forState: .Normal)
  } 
}

Or with ActionKit, all in one place

button.addControlEvent(.touchUpInside) { (control: UIControl) in
  guard let button = control as? UIButton else {
    return
  }
  button.setTitle("Button was tapped!", forState: .Normal)

}

Installation

CocoaPods

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

pod 'ActionKit', '~> 2.5.2'

Carthage

    1. Add the following to your Cartfile:
    github "ActionKit/ActionKit" == 2.5.2

How it works

ActionKit extends target-action functionality by providing easy to use methods that take closures instead of a selector. ActionKit uses a singleton which stores the closures and acts as the target. Closures capture and store references to any constants and variables from their context, so the user is free to use variables from the context in which the closure was defined in.

Features

  • Add an action based closure to any UIGestureRecognizer subclass (eg. UITapGestureRecognizer, UIPanGestureRecognizer...) instead of needing to use the target-action mechanism
  • Remove actions added to UIGestureRecognizer subclasses
  • Add an action based closure to any UIControl subclass (eg: UIButton, UIView, UISwitch...) instead of needing to use the target-action mechanism
  • For UIControls, add an action for any number of controlEvents
  • Remove actions added to UIControl subclasses
  • Add an action based closure to any UIBarButtonItem, instead of needing target-action
  • Remove actions added to UIBarButtonItems

Examples

See the examples wiki

Changelog

See the changelog here

License

Licensed under the terms of the MIT license. See LICENSE file

actionkit's People

Contributors

andreividrasco avatar aureltyson avatar brandons avatar coolbnjmn avatar irlabs avatar manuege avatar mattijsf avatar maxwellainatchi avatar objcolumnist avatar ppeelen avatar readmecritic avatar romanpodymov avatar thisiskevinchoi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

actionkit's Issues

Swift 3 Version

Will you guys support swift 3 in ActionKit soon ? I love this library and used in a couple of projects of mine.

Swift 4

Any updates on the progress to update this for Swift 4?

ActionKit.swift:118:30: Instance method 'append' expects a single parameter of type '(String, ActionKitClosure)'

gestureArr.append(name, closure) should be gestureArr.append((name, closure))

Making this available on cocoapods

Hey guys, Are you guys thinking about making this available on cocoapods. If not would you accept a pull request from me to make it cocoapods compatible?

Failed to build Pod using new XCode 9 build system

error: unable to build node: '/Users/mitusha/Library/Developer/Xcode/DerivedData/Seequre-gbaihqjeapccgubvlatqubgeiupx/Build/Products/Debug-
iphonesimulator/ActionKit/ActionKit.framework/Info.plist' (node is produced by multiple commands; 
e.g., '28cc143554b842798526fb3db67e8978c7a51e241ce7f43b101647fcd45d59e0:CopyPlistFile 
/Users/mitusha/Library/Developer/Xcode/DerivedData/Seequre-
gbaihqjeapccgubvlatqubgeiupx/Build/Products/Debug-iphonesimulator
/ActionKit/ActionKit.framework/Info.plist /Users/mitusha/unicreo/seequre-ios/Pods/ActionKit/ActionKit/Info.plist' and 
'28cc143554b842798526fb3db67e8978c7a51e241ce7f43b101647fcd45d59e0:ProcessInfoPlistFile 
/Users/mitusha/Library/Developer/Xcode/DerivedData/Seequre-gbaihqjeapccgubvlatqubgeiupx/Build/Products/Debug-
iphonesimulator
/ActionKit/ActionKit.framework/Info.plist /Users/mitusha/unicreo/seequre-
ios/Pods/Target Support Files/ActionKit/Info.plist')

This could be easily resolved by manual deleting of duplicated info.plist in pod folder.

Version 2.2.0

Could you please fix it?

Licensing

I'd like to know if this project is MIT licensed or something similar. I'd like to use it in a project but I can't do this if it doesn't have an explicit license.

Thanks.

Memory leak

If you don't remove closure manual, it will referenced by ActionKitSingleton.sharedInstance, so the closure will never dealloc even when button is dealloced.

to solve this problem , you may have to add the closure to UIButton, like BlocksKit(https://github.com/zwaldowski/BlocksKit) did

When using on a text field inputView

I use action kit on a UIDatePicker as follows:

fileprivate func setupDatePicker(on textField: UITextField, mode: UIDatePickerMode = .date) {
    let datePicker = UIDatePicker()
    datePicker.date = Date()
    datePicker.datePickerMode = mode
    datePicker.setValue(UIColor.cs_CongressBlue(), forKeyPath: "textColor")
    datePicker.backgroundColor = UIColor(red: 245/255, green: 245/255, blue: 245/255, alpha: 1.0)
    datePicker.addControlEvent(.valueChanged) { [unowned datePicker, unowned self] in
        if mode == .countDownTimer {
            textField.text = "\(Int(datePicker.countDownDuration/60)) Minutes"
        } else {
            textField.text = self.dateFormatter.string(from: datePicker.date)
        }
    }
    
    textField.inputView = datePicker
}

The way Apple handles input views if they are removed when changing to another input view.
This result in calling removeFromSuperview() and in turn clearActionKit(). Which means the next time the input view is presented - there no actions.

Support for multiple events

In Obj-C, we have possibility to add target, for example
UIControlEventTouchDown | UIControlEventTouchUpInside

In Swift, for this option we should use array
[.TouchUpInside, .TouchDown]

button.addControlEvent([.TouchUpInside, .TouchDown], closure: {})
doesn't show error on compile time, but actions is not added to button

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.