Created
November 25, 2020 10:32
-
-
Save Otbivnoe/6cc3c114ec99aef62349d1a3617b001f to your computer and use it in GitHub Desktop.
Subviews builder
This file contains 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
@_functionBuilder | |
struct SubviewsBuilder { | |
static func buildBlock(_ views: UIView...) -> [UIView] { | |
return views | |
} | |
} | |
extension UIView { | |
func addSubviews(@SubviewsBuilder _ subviews: () -> [UIView]) -> UIView { | |
subviews().forEach { addSubview($0) } | |
return self | |
} | |
} | |
let view = UIView() | |
let containerView = UIView() | |
view.addSubviews { | |
containerView.addSubviews { | |
UIView() | |
UIView() | |
} | |
UIView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment