ios - NSParagraphStyle 属性名称 : Conversion from swift 3 to swift 4. 2

标签 ios swift type-conversion

你好,我目前正在按照教程向我的 textView 添加一些 NSformatting,但我有点卡在一行代码上我认为代码是在 swift 3 上编写的,我在 swift 4.2 上,这是一行代码swift 3 上的代码:

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

我发现最连贯的方法是:

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

但我仍然得到错误:没有更多内容,表达式类型不明确

我做错了什么?

最佳答案

首先 addAttributes:value:range (复数)甚至在 Swift 3 中都不存在

NSParagraphStyleAttributeName 已更改为 NSAttributedString.Key.paragraphStyle

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

关于ios - NSParagraphStyle 属性名称 : Conversion from swift 3 to swift 4. 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52545655/

相关文章:

ios - iOS数据导入策略/设计

ios - 自动布局黄色警告。它会使我的应用程序在运行时崩溃吗

ios - UIView.animate 无法在 swift 中正常工作

c - 在 C 中实现动态类型

iphone - iOS - RestKit 并清除所有数据?

json - 快速解析响应时出现问题?

ios - 如何将 indexPath 值从 performSegue() 传递到 prepareForSegue()

java - 仅当输入为 "true"或 "false"时才将字符串转换为 boolean 值

error-handling - 怎么样了?运算符与 From 特征交互?

ios - Xcode 链接框架错误?