Skip to content

Instantly share code, notes, and snippets.

@astrokin
Forked from maxsokolov/With.swift
Created February 10, 2018 08:53
Show Gist options
  • Save astrokin/59db2496d26f239a7f59b847fb327fe7 to your computer and use it in GitHub Desktop.
Save astrokin/59db2496d26f239a7f59b847fb327fe7 to your computer and use it in GitHub Desktop.
public func with<T>(_ item: inout T, action: (inout T) -> Void) {
action(&item)
}
public func with<T>(_ item: T, action: (T) -> Void) {
action(item)
}
public func with<T: AnyObject>(_ item: T, action: (T) -> Void) {
action(item)
}
/**
* Instead of:
*
* attributes.frame.size = CGSize(width: size.width + 10, height: 23)
* attributes.frame.left = attributes.iconViewFrame.right + 8
* attributes.frame.top = 8
*
* use:
*
* with(&attributes.frame) {
* $0.size = CGSize(width: size.width + 10, height: 23)
* $0.left = attributes.iconViewFrame.right + 8
* $0.top = 8
* }
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment