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?

Roman Podymov
  • 4,168
  • 4
  • 30
  • 57
  • 1
    I don't get any error from that line when copied into a Swift 4.2 playground in Xcode 10.1. – rmaddy Mar 07 '19 at 17:18
  • 1
    Works for me too. Maybe clean and build. Seems someone else also came across this [here](https://github.com/delba/TextAttributes/pull/7) but that was quite a while back. Anyways, try `NSMutableAttributedString(string: "")` – staticVoidMan Mar 07 '19 at 17:36
  • @staticVoidMan Thanks. I use SwiftyAttributes 4.3.0 and I cannot understand why this version does not work for me. – Roman Podymov Mar 09 '19 at 16:11

1 Answers1

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.

Roman Podymov
  • 4,168
  • 4
  • 30
  • 57