如何解决"模糊地使用下标"错误?

时间:2016-02-19 11:35:05

标签: ios swift avfoundation

我在Swift中遇到问题,我的代码工作正常。导入AVFoundation后,我收到ambiguous use of subscript

item错误

我从这里找到了原因: Ambiguous use of ‘subscript’ error when importing AVFoundation

但是,我似乎无法根据那里提供的答案解决问题。

这是我的代码:

self.resultsVideoDurations_DICT = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as! Dictionary<NSObject, AnyObject>

let item = self.resultsVideoDurations_DICT["items"] as AnyObject!

let key  =  ( ( ( item[0] as! Dictionary<NSObject, AnyObject>)["snippet"] as! Dictionary<NSObject, AnyObject> )["publishedAt"] as? String)!

let value = ( ( item[0] as! Dictionary<NSObject, AnyObject>)["contentDetails"] as! Dictionary<NSObject, AnyObject> )["duration"] as? String

我试过以下(项目[0])!但这给了我警告:

  

来自&#39; AUAudioUnitBus&#39;不相关的类型&#39;字典&#39;总是失败

我该如何解决这个问题?感谢

1 个答案:

答案 0 :(得分:0)

只需将item转换为您要强制执行的类型:

let item = self.resultsVideoDurations_DICT["items"] as! [Dictionary<NSObject, AnyObject>]

let key  =  ( ( ( item[0])["snippet"] as! Dictionary<NSObject, AnyObject> )["publishedAt"] as? String)!

let value = ( ( item[0])["contentDetails"] as! Dictionary<NSObject, AnyObject> )["duration"] as? String

这似乎是在操场上清除它。