-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b5dcbb
commit 5b819df
Showing
1 changed file
with
18 additions
and
0 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
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 {} |