You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if you would want to support this kind of use-case, but consider the following.
Here is a bunch of some of the more convoluted string formation we have.
letdescAttrStrBuilder= promotion.dealDescription.stylize().color(.normalContentTitle()).font(.preferredFont(forTextStyle:.subheadline))
if promotion.isPromotionActionable {
descAttrStrBuilder.underline(.single)}letdescAttrStr= descAttrStrBuilder.attr
varvalidUntil:String?
if let endsDate = promotion.offerEndsDate {letendsDateString=DateFormatter.localizedString(from: endsDate, dateStyle:.short, timeStyle:.none)
validUntil ="\nOffer Ends: \(endsDateString)"}letendDateAttrStr= validUntil.stylize().color(.normalContentSubTitle()).font(.preferredFont(forTextStyle:.footnote)).attr
titleLabel.attributedText = descAttrStr + endDateAttrStr
for the promotion.isPromotionActionable block - I wonder if this is something that could be made a 'first class' citizen of the current StringStylizer DSL.
What I mean by this is, It would be cool to write that if block 'in-line' like one of the below two syntaxes.
Option 1 - would mean adding more state into StringStylizer - when a conditionally() is used, you would need to evaluate that in the next 'style code' call (i.e. underline()) and then reset it.
The only issue I have with this is if there is more than 1 'style code' method called. i.e. stylizer.conditionally(true).underline(.single).color(black)
Does the conditional apply to both underline() and color()?
That question is something that this syntax couldn't really communicate unless you were to change conditionally to conditionallySingle() and conditionallyAll() or something like this. It still isn't necessarily natural to consume though.
Option 2 - would be probably easier to understand as a framework consumer - and perhaps could be optional and default to nil or true :). It is not quite as pretty looking as option 1 however.
Either way would involve a pretty decent rewrite. I would be happy to help out if you like such a suggestion.
Or alternatively, of course, you could suggest a better way to write the above snippet 😬
The text was updated successfully, but these errors were encountered:
Hey Kazuhiro,
I'm not sure if you would want to support this kind of use-case, but consider the following.
Here is a bunch of some of the more convoluted string formation we have.
for the
promotion.isPromotionActionable
block - I wonder if this is something that could be made a 'first class' citizen of the current StringStylizer DSL.What I mean by this is, It would be cool to write that if block 'in-line' like one of the below two syntaxes.
OR
Option 1 - would mean adding more state into StringStylizer - when a
conditionally()
is used, you would need to evaluate that in the next 'style code' call (i.e.underline()
) and then reset it.The only issue I have with this is if there is more than 1 'style code' method called. i.e.
stylizer.conditionally(true).underline(.single).color(black)
Does the conditional apply to both
underline()
andcolor()
?That question is something that this syntax couldn't really communicate unless you were to change conditionally to
conditionallySingle()
andconditionallyAll()
or something like this. It still isn't necessarily natural to consume though.Option 2 - would be probably easier to understand as a framework consumer - and perhaps could be optional and default to
nil
ortrue
:). It is not quite as pretty looking as option 1 however.Either way would involve a pretty decent rewrite. I would be happy to help out if you like such a suggestion.
Or alternatively, of course, you could suggest a better way to write the above snippet 😬
The text was updated successfully, but these errors were encountered: