Search code examples
iosxcodeswiftswift2xcode7-beta5

Using Object Initializers in Swift to replace AllocWithZone


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?


Solution

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

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