Skip to content

Instantly share code, notes, and snippets.

@chosa91
Forked from krzyzanowskim/with.swift
Created February 28, 2020 08:48
Show Gist options
  • Save chosa91/3dd84e9b74cfb449692af8e54efec284 to your computer and use it in GitHub Desktop.
Save chosa91/3dd84e9b74cfb449692af8e54efec284 to your computer and use it in GitHub Desktop.
@discardableResult
public func with<T>(_ value: T, _ builder: (T) -> Void) -> T {
builder(value)
return value
}
@discardableResult
public func with<T>(_ value: T, _ builder: (T) throws -> Void ) rethrows -> T {
try builder(value)
return value
}
// Use
with(self.collectionView) {
$0.dataSource = self
$0.delegate = self
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment