arowmy初始化工作正常斯威夫特<2,但是在斯威夫特2我从Xcode中的错误消息Call can throw, but it is not marked with 'try' and the error is not handled的let anyObj = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as! [String:AnyObject].我认为在我的情况下我不能使用try catch块,因为此时super尚未初始化."尝试"需要一个抛出的功能.
这是我的功能:
required init(coder aDecoder : NSCoder)
{
self.name = String(stringInterpolationSegment: aDecoder.decodeObjectForKey("name") as! String!)
self.number = Int(aDecoder.decodeIntegerForKey("number"))
self.img = String(stringInterpolationSegment: aDecoder.decodeObjectForKey("image") as! String!)
self.fieldproperties = []
var tmpArray = [String]()
tmpArray = aDecoder.decodeObjectForKey("properties") as! [String]
let c : Int = tmpArray.count
for var i = 0; i < c; i++
{
let data …Run Code Online (Sandbox Code Playgroud)