Skip to content

Commit

Permalink
feat(Apply): create protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
marionauta committed Nov 2, 2020
1 parent 7b5dcbb commit 5b819df
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Sources/HelperKit/Protocols/Apply.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation

public protocol Apply {}

public extension Apply where Self: AnyObject {
/// Calls the closure with `self` as its argument and returns `self`.
///
/// let button = UIButton(type: .system).apply {
/// $0.setTitleColor(.black, for: .normal)
/// $0.setTitleColor(.gray, for: .disabled)
/// }
@inlinable func apply(closure: (Self) -> Void) -> Self {
closure(self)
return self
}
}

extension NSObject: Apply {}

0 comments on commit 5b819df

Please sign in to comment.