问题描述
Xcode 8 beta 4 不再识别 Foundation 类 AttributedString
.
Xcode 8 beta 4 no longer recognizes Foundation class AttributedString
.
我在这个简单的游乐场示例中复制了它:
I've reproduced it in this simple playground example:
//: 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 中的某些源代码错误?
Since AttributedString
was available in older Xcode 8 Swift 3 betas, I imagine this is a Foundation
bug that needs to be fixed, rather than some source code error in Playground?
推荐答案
虽然在 Xcode 发行说明中没有记录,但 Swift 进化提案的第 2 版更新 SE-0086 在 Swift Foundation 中删除 NS 前缀 已将NS"前缀添加回几个先前删除前缀的 Foundation 类.
Although undocumented in the Xcode release notes, a version 2 update to Swift evolution proposal SE-0086 Drop NS Prefix in Swift Foundation has added the "NS" prefix back to several Foundation classes which previously dropped the prefix.
原因如下:
如果该类计划在不久的将来具有等效的值类型,则保留 NS 前缀.示例:NSAttributedString、NSRegularExpression、NSPredicate.
因此,Swift AttributedString
类型将在 某个 点返回,作为结构,而不是类.
So, the Swift AttributedString
type will return at some point, as a struct next time, instead of being a class.
听起来其中一些改进将成为Swift 4 的重点领域".现在,有必要恢复使用 NSAttributedString
类.
It sounds like some of these improvements will be "a focus area for Swift 4." For now, it's necessary to revert back to using the NSAttributedString
class.
如果您想知道 SE-0086 v2 更新影响了多少类型,它看起来像 修订版 影响了之前在 Swift 3 中删除 NS 前缀的大约 32 种类型.
If you're curious to know how many types were affected by the SE-0086 v2 update, it looks like the revision affects ~32 types which had previously dropped the NS prefix for Swift 3.
这篇关于使用未声明的类型 'AttributedString'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!