问题描述
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更新已将"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.
原因如下:
因此,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更新影响了多少种类型,看起来就像影响〜32种以前为Swift 3删除了NS前缀的类型.
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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!