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
| @resultBuilder | |
| struct MultipleChildBuilder { | |
| ... | |
| static func buildArray(_ components: [[DocumentElement]]) -> [DocumentElement] { | |
| components.flatMap { $0 } | |
| } | |
| } |
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
| let document = Document { | |
| for index in 1...3 { | |
| Label(text: "Section \(index)").size(.subtitle) | |
| Label(text: "A text").size(.body) | |
| } | |
| } |
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
| let document = Document { | |
| switch value { | |
| case 1: | |
| Label(text: "Line 1") | |
| case 2: | |
| Label(text: "Line 2") | |
| case 3: | |
| Label(text: "Line 3") | |
| default: | |
| Label(text: "Line") |
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
| @resultBuilder | |
| struct MultipleChildBuilder { | |
| ... | |
| static func buildEither(first component: [DocumentElement]) -> [DocumentElement] { | |
| return component | |
| } | |
| static func buildEither(second component: [DocumentElement]) -> [DocumentElement] { | |
| return component | |
| } |
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
| let document = Document { | |
| if hasLogo { | |
| Logo(imageName: "CompanyLogo.png") | |
| } else { | |
| Label(text:"Title").size(.title) | |
| } | |
| Label(text:"Another line of text") | |
| } |
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
| let document = Document ( | |
| //The problem lies on this convertion | |
| [DocumentElement] | |
| //Those are OK! | |
| DocumentElement | |
| DocumentElement | |
| ) |
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
| let circuit = SeriesCircuit ( | |
| [ Resistor(resistance: 7.0), | |
| ParallelCircuit(...) ] | |
| } |
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
| let circuit = SeriesCircuit { | |
| Resistor(resistance: 7.0) | |
| ParallelCircuit ( | |
| [Resistor(resistance: 10.0), | |
| SeriesCircuit(...)] ) | |
| } |
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
| let circuit = SeriesCircuit { | |
| Resistor(resistance: 7.0) | |
| ParallelCircuit { | |
| Resistor(resistance: 10.0) | |
| SeriesCircuit ( | |
| [Resistor(resistance: 6.0), | |
| Resistor(resistance: 4.0)]) | |
| } | |
| } |
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
| @resultBuilder | |
| struct MultipleChildBuilder { | |
| ... | |
| static func buildOptional(_ component: DocumentElementConvertible?) -> [DocumentElement] { | |
| return component?.asElements() ?? [] | |
| } | |
| } |