SwiftRichString icon indicating copy to clipboard operation
SwiftRichString copied to clipboard

Setting a StyleGroup through an array strips the tags.

Open marcopax opened this issue 6 years ago • 0 comments

Hello, I'm trying to set multiple styles for an attributed string, but I'm facing problems when I try to set a StyleGroup through an array. To replicate the problem in a controlled environment, I created a new project from scratch and added the library as a pod; then I try to apply the style to a text:

Preparation steps:

let redStyle = Style {
    $0.color = UIColor.red
}
let myStyleGroup = StyleGroup(base: nil, ["red": redStyle])
let myText = "Hello, <red>this is red text</red>."

Applying the myStyleGroup as a single style works perfectly:

label.attributedText = myText.set(style: myStyleGroup)

Applying the myStyleGroup as an array of styles doesn't work:

label.attributedText = myText.set(styles: [myStyleGroup])

I tried to debug it and seems that the tag configuration is stripped out after calling the internal mergeStyles method.

I've created a repository to show the problem.

marcopax avatar Apr 04 '19 11:04 marcopax