Skip to content

Instantly share code, notes, and snippets.

@kimar kimar/Applicable.swift
Last active Jan 10, 2020

What would you like to do?
Implement `apply` on NSObject (and other types)
import Foundation
protocol Applicable {}
extension NSObject: Applicable {}
extension Applicable {
func apply(_ closure: (Self) -> Void) -> Self {
return self
extension Array where Element: NSObject {
func apply(_ closure: (Element) -> Void) -> [Element] {
forEach { closure($0) }
return self

This comment has been minimized.

Copy link

dkyowell commented Jan 10, 2020

Thanks for sharing. This is my favorite tip from the past year.

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.