Chris
Chris

Reputation: 67

NSParagraphStyleAttributeName : Conversion from swift 3 to swift 4.2

Hello I am currently adding some NSformatting to my textView following a tutorial, but I'm kind of stuck on a code of line I think the code was written on swift 3, I am on swift 4.2, here is the line of code on swift 3 :

attributedText.addAttributes(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: 0, length: length))

The most coherent way I found was:

 attributedText.addAttributes([NSAttributedString.value(forKey: paragraphStyle)], range: NSRange(location: 0
            , length: length))

But still I get the error: Type of expression is ambiguous without more content

What I am doing wrong?

Upvotes: 1

Views: 701

Answers (1)

vadian
vadian

Reputation: 285260

First of all addAttributes:value:range (plural) doesn't exist not even in Swift 3

NSParagraphStyleAttributeName has been changed to NSAttributedString.Key.paragraphStyle

attributedText.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: length))

Upvotes: 4

Related Questions