在Swift中使用对象初始化程序替换AllocWithZone [英] Using Object Initializers in Swift to replace AllocWithZone

查看:330
本文介绍了在Swift中使用对象初始化程序替换AllocWithZone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将Xcode从Xcode 7 beta 4更新为Xcode 7 beta 5,开始出现以前没有的错误.那就是:"AllocWithZone在Swift中不可用:请改用Object Initializers."

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
}

我可以用什么代替".allocWithZone",以便它使用对象初始化程序而不是此Obj C组件?

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

推荐答案

我使用了它,iOS Charts库对我有用:

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

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

这篇关于在Swift中使用对象初始化程序替换AllocWithZone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆