Created
May 7, 2026 20:01
-
-
Save sebjvidal/6cfe480ccce613d6225144833a0d4cef to your computer and use it in GitHub Desktop.
NSLayoutConstraint Result Builder
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 UIKit | |
| @resultBuilder | |
| struct NSLayoutConstraintBuilder { | |
| static func buildBlock(_ components: [NSLayoutConstraint]...) -> [NSLayoutConstraint] { | |
| components.flatMap { $0 } | |
| } | |
| static func buildExpression(_ expression: NSLayoutConstraint) -> [NSLayoutConstraint] { | |
| [expression] | |
| } | |
| static func buildExpression(_ expression: [NSLayoutConstraint]) -> [NSLayoutConstraint] { | |
| expression | |
| } | |
| static func buildOptional(_ component: [NSLayoutConstraint]?) -> [NSLayoutConstraint] { | |
| component ?? [] | |
| } | |
| static func buildEither(first component: [NSLayoutConstraint]) -> [NSLayoutConstraint] { | |
| component | |
| } | |
| static func buildEither(second component: [NSLayoutConstraint]) -> [NSLayoutConstraint] { | |
| component | |
| } | |
| static func buildArray(_ components: [[NSLayoutConstraint]]) -> [NSLayoutConstraint] { | |
| components.flatMap { $0 } | |
| } | |
| static func buildLimitedAvailability(_ component: [NSLayoutConstraint]) -> [NSLayoutConstraint] { | |
| component | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment