Using Object Initializers in Swift to replace AllocWithZone

爱⌒轻易说出口 提交于 2019-12-23 16:23:28

问题


I recently updated my Xcode from Xcode 7 beta 4 to Xcode 7 beta 5 and began to have an error that wasn't present before. That being: "AllocWithZone is unavailable in Swift: use Object Initializers instead."

Here is the code where the error is found:

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

What do I substitute in place of ".allocWithZone" so that it utilizes an Object Initializer instead of this Obj C component?


回答1:


I used this, and the iOS Charts library works for me:

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


来源:https://stackoverflow.com/questions/31885231/using-object-initializers-in-swift-to-replace-allocwithzone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!