AndreyArzhannikov / StringAttributesBuilder

Build attributed strings easily using chaining syntax
1 stars 0 forks source link

Cannot use .init() syntax for builders #1

Open AndreyArzhannikov opened 4 years ago

AndreyArzhannikov commented 4 years ago

Currently there is an error when you try to use .init() syntax for builder. The following error message is occurred: Expression type 'NSAttributedString' is ambiguous without more context

It's supposed to be swift compiler cannot infer type, so it requires to specify explicit type

Example triggering issue

textView.attributedText = "Hello, Apple!".attributed(builder: .init()
    .foreground(color: .gray)
    .background(color: .green)
)

image

Environment:

AndreyArzhannikov commented 4 years ago

We might use closure based building attributes like this:

func attributed(building: (AttributesBuilder) -> AttributesBuilder) -> NSAttributedString {
        attributed(with: building(AttributesBuilder()).attributes)
    }

"Some string".attributed {
            $0.foreground(color: .black)
                .background(color: .blue)
                .font(.systemFont(ofSize: 16))
        }

aka snapkit style for adding constraints