-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from takasek/swiftpm
Swift Package Manager compatibility
- Loading branch information
Showing
4 changed files
with
118 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// Extensions_UIKit.swift | ||
// ActionClosurable | ||
// | ||
// Created by Yoshitaka Seki on 2016/04/11. | ||
// Copyright © 2016年 Yoshitaka Seki. All rights reserved. | ||
// | ||
|
||
#if os(iOS) | ||
import UIKit | ||
|
||
extension ActionClosurable where Self: UIControl { | ||
public func on(_ controlEvents: UIControl.Event, closure: @escaping (Self) -> Void) { | ||
convert(closure: closure, toConfiguration: { | ||
self.addTarget($0, action: $1, for: controlEvents) | ||
}) | ||
} | ||
} | ||
|
||
extension ActionClosurable where Self: UIButton { | ||
public func onTap(_ closure: @escaping (Self) -> Void) { | ||
on(.touchUpInside, closure: closure) | ||
} | ||
} | ||
|
||
public extension ActionClosurable where Self: UIRefreshControl { | ||
func onValueChanged(closure: @escaping (Self) -> Void) { | ||
on(.valueChanged, closure: closure) | ||
} | ||
|
||
init(closure: @escaping (Self) -> Void) { | ||
self.init() | ||
onValueChanged(closure: closure) | ||
} | ||
} | ||
|
||
|
||
extension ActionClosurable where Self: UIGestureRecognizer { | ||
public func onGesture(_ closure: @escaping (Self) -> Void) { | ||
convert(closure: closure, toConfiguration: { | ||
self.addTarget($0, action: $1) | ||
}) | ||
} | ||
public init(closure: @escaping (Self) -> Void) { | ||
self.init() | ||
onGesture(closure) | ||
} | ||
} | ||
|
||
extension ActionClosurable where Self: UIBarButtonItem { | ||
public init(title: String, style: UIBarButtonItem.Style, closure: @escaping (Self) -> Void) { | ||
self.init() | ||
self.title = title | ||
self.style = style | ||
self.onTap(closure) | ||
} | ||
public init(image: UIImage?, style: UIBarButtonItem.Style, closure: @escaping (Self) -> Void) { | ||
self.init() | ||
self.image = image | ||
self.style = style | ||
self.onTap(closure) | ||
} | ||
public init(barButtonSystemItem: UIBarButtonItem.SystemItem, closure: @escaping (Self) -> Void) { | ||
self.init(barButtonSystemItem: barButtonSystemItem, target: nil, action: nil) | ||
self.onTap(closure) | ||
} | ||
public func onTap(_ closure: @escaping (Self) -> Void) { | ||
convert(closure: closure, toConfiguration: { | ||
self.target = $0 | ||
self.action = $1 | ||
}) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// swift-tools-version:5.1 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ActionClosurable", | ||
products: [ | ||
// Products define the executables and libraries produced by a package, and make them visible to other packages. | ||
.library( | ||
name: "ActionClosurable", | ||
targets: ["ActionClosurable"]), | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages which this package depends on. | ||
.target( | ||
name: "ActionClosurable", | ||
path: "ActionClosurable" | ||
), | ||
.testTarget( | ||
name: "ActionClosurableTests", | ||
path: "ActionClosurableTests" | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters