使用未声明的类型'AttributedString' [英] Use of undeclared type 'AttributedString'
问题描述
Xcode 8 beta 4不再识别基础类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更新
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.
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
类型将在 some 点返回,作为下一次结构,而不是作为类.
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更新影响了多少种类型,看起来就像
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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!