swift - 使用未声明的类型 'AttributedString'

标签 swift xcode swift3 xcode8-beta4

Xcode 8 beta 4 不再识别基础类 AttributedString

我在这个简单的 Playground 示例中复制了它:

//: Playground - noun: a place where people can play

import Foundation

let attrStr1 = NSAttributedString()
let attrStr2 = AttributedString()  // Use of undeclared type 'AttributedString'

由于 AttributedString 在旧的 Xcode 8 Swift 3 beta 中可用,我想这是一个需要修复的 Foundation 错误,而不是 Playground 中的一些源代码错误?

最佳答案

虽然在 Xcode 发行说明中没有记录,但 Swift 进化提案的版本 2 更新 SE-0086 Drop NS Prefix in Swift Foundation已将“NS”前缀添加回之前删除前缀的几个基础类。

原因如下:

If the class is planned to have a value-type equivalent in the near future, then keep the NS prefix. Examples: NSAttributedString, NSRegularExpression, NSPredicate.

因此,Swift AttributedString 类型将在某个 点作为下一次的结构返回,而不是类。

听起来这些改进中的一些将成为“Swift 4 的重点领域”。现在,有必要恢复使用 NSAttributedString 类。

如果您想知道有多少类型受到 SE-0086 v2 更新的影响,它看起来像 revision影响之前为 Swift 3 删除 NS 前缀的约 32 种类型。

关于swift - 使用未声明的类型 'AttributedString',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38710786/

相关文章:

ios - 如何在 SwiftUI 中将 View() 作为列表的一部分传递?

swift - TableViewController中,显示的数据错误

iphone - xcode 中的 touch/untouch 是做什么的?

xcode - 在Mac上安装OpenCV错误

ios - 如何将NSArray转换为String swift3?

swift - 从磁盘加载文件的问题

swift - Swinject:生成任何对象的实例(对于未注册的对象、ViewModel 等...)

swift - 闭包如何捕获数据?

json - NSJSONSerialization - 无法在 Swift 上将数据转换为字符串

xcode - 如何在 Xcode 中将 NSClickGestureRecogniser 与 Swift 一起使用?