BlazeWidgetLabel - iOS
BlazeWidgetLabel builds the label expression that decides which content a widget shows. Use it to target a single label, or to combine labels with logical AND and OR conditions.
Pass the expression to the .labels case of BlazeDataSourceType:
let dataSource: BlazeDataSourceType = .labels(BlazeWidgetLabel.mustInclude("football", "highlights"))How expressions compose
All BlazeWidgetLabel methods are static, and each one returns a new BlazeWidgetLabel. You build a complex expression by nesting: create a sub-expression first, then pass it into another method as an argument.
Methods can't be chained. mustInclude("for-you").atLeastOneOf("player", "team") doesn't compile, because the methods are static rather than instance methods. To express "for-you AND (player OR team)", nest the OR inside the AND:
let playerOrTeam = BlazeWidgetLabel.atLeastOneOf("player", "team")
let forYouAndEither = BlazeWidgetLabel.mustInclude(BlazeWidgetLabel.singleLabel("for-you"), playerOrTeam)Both mustInclude and atLeastOneOf accept either strings or other BlazeWidgetLabel expressions, and each form takes a comma-separated list or an array.
| Method | Logic | Accepts |
|---|---|---|
singleLabel(_:) | A single label | One string |
mustInclude(_:) | AND: every operand must match | Strings or expressions, as a list or an array |
atLeastOneOf(_:) | OR: at least one operand must match | Strings or expressions, as a list or an array |
Single label
let singleLabel = BlazeWidgetLabel.singleLabel("Blue")Matches content labeled Blue.
AND expressions
Use mustInclude when every label must be present.
let andExpression = BlazeWidgetLabel.mustInclude("Blue", "Green")Matches only content that has both Blue and Green.
To combine expressions rather than strings, pass the expressions as arguments or as an array. Both forms produce the same result:
let red = BlazeWidgetLabel.singleLabel("Red")
let blueOrGreen = BlazeWidgetLabel.atLeastOneOf("Blue", "Green")
let combined = BlazeWidgetLabel.mustInclude(red, blueOrGreen)
let combinedFromArray = BlazeWidgetLabel.mustInclude([red, blueOrGreen])Matches content that has Red, and also has either Blue or Green.
OR expressions
Use atLeastOneOf when any one of the labels is enough.
let orExpression = BlazeWidgetLabel.atLeastOneOf("Blue", "Green")Matches content that has Blue, Green, or both.
Expressions combine the same way as with mustInclude:
let red = BlazeWidgetLabel.singleLabel("Red")
let blueOrGreen = BlazeWidgetLabel.atLeastOneOf("Blue", "Green")
let orCombined = BlazeWidgetLabel.atLeastOneOf(red, blueOrGreen)
let orCombinedFromArray = BlazeWidgetLabel.atLeastOneOf([red, blueOrGreen])Matches content that has Red, or Blue, or Green.
Nesting to any depth
Nest expressions to build more specific targeting. This example matches content that carries any two of the three labels:
let one = BlazeWidgetLabel.singleLabel("test-1")
let four = BlazeWidgetLabel.singleLabel("test-4")
let seven = BlazeWidgetLabel.singleLabel("test-7")
let anyTwo = BlazeWidgetLabel.atLeastOneOf(
BlazeWidgetLabel.mustInclude(one, four),
BlazeWidgetLabel.mustInclude(four, seven),
BlazeWidgetLabel.mustInclude(one, seven)
)Related
Updated 22 days ago
