Skip to content

Instantly share code, notes, and snippets.

@akatkov7
Created March 26, 2018 18:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akatkov7/1b3efcea3efe8a1f136676aa85e07a2f to your computer and use it in GitHub Desktop.
Save akatkov7/1b3efcea3efe8a1f136676aa85e07a2f to your computer and use it in GitHub Desktop.
Adds Kotlin-esque apply/with to Swift
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