Created
March 26, 2018 18:25
-
-
Save akatkov7/1b3efcea3efe8a1f136676aa85e07a2f to your computer and use it in GitHub Desktop.
Adds Kotlin-esque apply/with to Swift
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
import Foundation | |
protocol ApplyProtocol { } | |
extension NSObject: ApplyProtocol { } | |
extension ApplyProtocol { | |
@discardableResult func apply(closure: (Self) -> Void) -> Self { | |
closure(self) | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment