使用 Swift 中的对象初始值设定项来替换 AllocWithZone

Using Object Initializers in Swift to replace AllocWithZone

我最近将我的 Xcode 从 Xcode 7 beta 4 更新到 Xcode 7 beta 5 并开始出现以前不存在的错误。即:"AllocWithZone is unavailable in Swift: use Object Initializers instead."

这里是发现错误的代码:

public func copyWithZone(zone: NSZone) -> AnyObject {
    let copy = self.dynamicType.allocWithZone(zone) as ChartDataSet
    copy.colors = colors
    copy.label = self.label
    return copy
}

我应该用什么来代替“.allocWithZone”,以便它使用对象初始化程序而不是这个 Obj C 组件?

我用过这个,iOS 图表库适合我:

let copy=self.dynamicType.initialize() as! ChartDataEntry