Skip to content

Instantly share code, notes, and snippets.

@kimar kimar/Applicable.swift
Last active Oct 24, 2019

Embed
What would you like to do?
Implement `apply` on NSObject (and other types)
import Foundation
protocol Applicable {}
extension NSObject: Applicable {}
extension Applicable {
@discardableResult
func apply(_ closure: (Self) -> Void) -> Self {
closure(self)
return self
}
}
extension Array where Element: NSObject {
@discardableResult
func apply(_ closure: (Element) -> Void) -> [Element] {
forEach { closure($0) }
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.