简体   繁体   English

NSParagraphStyleAttributeName:从Swift 3到Swift 4.2的转换

[英]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 : 您好,我目前正在按照教程向我的textView中添加一些NSformatting,但是我有点卡在一行代码中,我认为代码是在swift 3上编写的,我是在swift 4.2上编写的,这是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? 我做错了什么?

First of all addAttributes:value:range (plural) doesn't exist not even in Swift 3 首先,即使在Swift 3中也不存在addAttributes:value:range (复数)

NSParagraphStyleAttributeName has been changed to NSAttributedString.Key.paragraphStyle NSParagraphStyleAttributeName已更改为NSAttributedString.Key.paragraphStyle

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM