0

I am trying to run the code I wrote some months ago. Now I use Swift 4.2/Xcode 10.1. I get the error Ambiguous use of 'init(string:attributes:)' on

let mutableAttributedString = NSMutableAttributedString(string: "", attributes: [:])

I also use SwiftyAttributes 4.3.0. Here I found public convenience init(string str: String, attributes: [Attribute]), but I cannot understand why Swift wants to call this function.

How can I solve this issue? Is it necessary to update SwiftyAttributes?

3
  • 1
    I don't get any error from that line when copied into a Swift 4.2 playground in Xcode 10.1. Commented Mar 7, 2019 at 17:18
  • 1
    Works for me too. Maybe clean and build. Seems someone else also came across this here but that was quite a while back. Anyways, try NSMutableAttributedString(string: "") Commented Mar 7, 2019 at 17:36
  • @staticVoidMan Thanks. I use SwiftyAttributes 4.3.0 and I cannot understand why this version does not work for me. Commented Mar 9, 2019 at 16:11

1 Answer 1

1

The problem was in the init method declared in SwiftyAttributes 4.3.0:

extension NSAttributedString {
    public convenience init(string str: String, attributes: [Attribute]) {
        self.init(string: str, attributes: dictionary(from: attributes))
    }
}

In SwiftyAttributes 5.0.0 this method was renamed to public convenience init(string str: String, swiftyAttributes attrs: [Attribute]). Therefore, I updated SwiftyAttributes to solve the problem. See this link for more detail about the fix added to SwiftyAttributes 5.0.0.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.