Created
          September 9, 2019 15:14 
        
      - 
      
- 
        Save ole/917b7d4570de534efd3fc974009c635c to your computer and use it in GitHub Desktop. 
    A replacement for let bindings in Swift function builders
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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