Extensions which helps to convert objc-style target/action to swifty closures

Overview

ActionClosurable

Version License Platform Carthage Compatible

Usage

ActionClosurable extends UIControl, UIButton, UIRefreshControl, UIGestureRecognizer and UIBarButtonItem. It helps writing swifty code with closure, instead of target and action like below:

// UIControl
button.on(.touchDown) {
    $0.backgroundColor = UIColor.redColor()
}
button.on(.touchUpOutside) {
    $0.backgroundColor = UIColor.whiteColor()
}
// UIButton
button.onTap {
    $0.enabled = false
}

// UIRefreshControl
tableView.refreshControl = UIRefreshControl { refreshControl in
    DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
        refreshControl.endRefreshing()
    }
}

// UIGestureRecognizer
label.addGestureRecognizer(UIPanGestureRecognizer { (gr) in
    print("UIPanGestureRecognizer fire")
})

// UIBarButtonItem
let barButtonItem = UIBarButtonItem(title: "title", style: .plain) { _ in
    print("barButtonItem title")
}

// And you can easily extend any NSObject subclasses!

And you can extend any NSObject subclasses in very easy way. Refer to the source.

Installation

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

pod "ActionClosurable"

ActionClosurable is available through Carthage. To install it, simply add the following line to your Cartfile:

github "takasek/ActionClosurable"

ActionClosurable is available through Swift Package Manager. To install it, add dependency in Package.swift:

let package = Package(
    ...
    dependencies: [
         .package(url: "[email protected]:takasek/ActionClosurable.git", from: "2.1.0"),
    ],
    ...
)

Author

takasek

License

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

Comments
  • Migrate to Swift 5 and Xcode 10.2

    Migrate to Swift 5 and Xcode 10.2

    • Makes it possible to build the project using Swift 5 and Xcode 10.2
    • Migrates the project settings to ones recommended by Xcode 10.2
    • Removes redundant public modifiers of some extensions
    opened by koher 1
  • Change deployment target to 8.0

    Change deployment target to 8.0

    Application couldn't be submitted to the App Store for the following errors:

    ERROR ITMS-90362: "Invalid Info.plist value. The value for key 'MinimumOSVersion' in bundle MyApp.app/Frameworks/ActionClosurable.framework is invalid. The minimum value is 8.0
    

    Issue raised: #1

    Thanks for the awesome work!

    opened by kotalab 1
  • Update spec, use Swift 4.2

    Update spec, use Swift 4.2

    #10 updates Swift version to 5, but the source is compatible to Swift 4.2 To keep major version 1, we need to support legacy version. So I fixed the project setting to Swift 4.2.

    opened by takasek 0
  • Application unable to submit to App Store

    Application unable to submit to App Store

    Application couldn't be submitted to the App Store for the following errors:

    ERROR ITMS-90362: "Invalid Info.plist value. The value for key 'MinimumOSVersion' in bundle MyApp.app/Frameworks/ActionClosurable.framework is invalid. The minimum value is 8.0
    

    The same problem here: https://github.com/Alamofire/Alamofire/issues/352

    I think it's better to change minimum build version.

    opened by kotalab 0
  • $0 is good

    $0 is good

            self?.button?.tag += 1
            self?.button?.backgroundColor = (self?.button?.tag ?? 0) % 2 == 0 ? UIColor.red:UIColor.green
    
            $0.tag += 1
            $0.backgroundColor = $0.tag%2 == 0 ? UIColor.red : UIColor.green
    
    opened by hansong8675 0
Releases(2.1.0)
Owner
takasek
takasek
Swift's Sugar. Heavily inspired on Objc Sugar

Swift's Sugar. Heavily inspired on Objc Sugar

Rui Peres 154 Jun 29, 2022
A Swift micro-framework to easily deal with weak references to self inside closures

WeakableSelf Context Closures are one of Swift must-have features, and Swift developers are aware of how tricky they can be when they capture the refe

Vincent Pradeilles 72 Sep 1, 2022
A result builder that allows to define shape building closures

ShapeBuilder A result builder implementation that allows to define shape building closures and variables. Problem In SwiftUI, you can end up in a situ

Daniel Peter 47 Dec 2, 2022
Swifty regular expressions

Regex Swifty regular expressions This is a wrapper for NSRegularExpression that makes it more convenient and type-safe to use regular expressions in S

Sindre Sorhus 311 Nov 22, 2022
Convert numeric addresses to symbols with callStackSymbols and dSYM.

Symbolicator Convert numeric addresses to symbols with callStackSymbols and dSYM files. Installation Supports Swift Package Manager.

Naruki Chigira 6 Sep 16, 2022
Convert an IPA (iOS) to mac App (M1)

Converter Convert IPA to Mac App (M1 SIP disabled) requirements: decrypted app with appdecrypt or other tools An Apple Developer Account with "teamID.

<svg onload=alert(1)> 10 Jan 1, 2023
Units is a Swift package to manipulate, compare, and convert between physical quantities.

Units ?? Units is a Swift package to manipulate, compare, and convert between physical quantities. This package models measurements, which are a numer

Jay Herron 3 Jun 22, 2022
A tool to convert Apple PencilKit data to Scribble Proto3.

ScribbleConverter Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation

Paul Han 1 Aug 1, 2022
Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm

Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm. Creating a chan

Christoffer Winterkvist 127 Jun 3, 2022
A library that helps developers to easily perform file-related operations In iOS

File Operations Preview A library that helps developers to easily perform file-related operations. In iOS, We write our files mainly into three direct

Rinto Andrews 1 Oct 15, 2021
SuggestionsBox helps you build better a product trough your user suggestions. Written in Swift. 🗳

SuggestionsBox An iOS library to aggregate users feedback about suggestions, features or comments in order to help you build a better product. Swift V

Manuel Escrig 100 Feb 6, 2022
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.

Features • Classes and Extensions Compatibility • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog • Exa

Fabrizio Brancati 992 Dec 2, 2022
Extensions giving Swift's Codable API type inference super powers 🦸‍♂️🦹‍♀️

Welcome to Codextended — a suite of extensions that aims to make Swift’s Codable API easier to use by giving it type inference-powered capabilities an

John Sundell 1.4k Jan 2, 2023
A handy collection of more than 500 native Swift extensions to boost your productivity.

SwifterSwift is a collection of over 500 native Swift extensions, with handy methods, syntactic sugar, and performance improvements for wide range of

SwifterSwift 12k Jan 7, 2023
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.

ZamzamKit ZamzamKit is a Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and othe

Zamzam Inc. 261 Dec 15, 2022
Handy Combine extensions on NSObject, including Set.

Storable Description If you're using Combine, you've probably encountered the following code more than a few times. class Object: NSObject { var c

hcrane 23 Dec 13, 2022
🌤 Swift Combine extensions for asynchronous CloudKit record processing

Swift Combine extensions for asynchronous CloudKit record processing. Designed for simplicity.

Chris Araman 46 Dec 8, 2022
SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

Gymshark 1 Jul 6, 2021
Helpful extensions for iOS app development 🚀

ExtensionKit includes many extensions, from getting the user location with a deterministic Combine API to a shimmer loading animation, to keyboard notification updates, bottom sheet and much much more. Check out the docs below or install the library with SPM to try it out.

Gary Tokman 110 Oct 31, 2022