Skip to content

Instantly share code, notes, and snippets.

@ole ole/let.swift
Created Sep 9, 2019

Embed
What would you like to do?
A replacement for let bindings in Swift function builders
import SwiftUI
func `let`<Value, Return>(_ expression: Value, body: (Value) -> Return) -> Return {
body(expression)
}
struct ContentView: View {
var body: some View {
GeometryReader { geometry in
`let`(geometry.size.width / 2) { lineWidth in
VStack {
Rectangle().fill(Color.red).frame(width: lineWidth)
Rectangle().fill(Color.green).frame(width: lineWidth)
Rectangle().fill(Color.blue).frame(width: lineWidth)
}
}
}
}
}
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.