通过Swift中的一系列字典循环

时间:2014-06-10 10:43:29

标签: arrays dictionary swift ios8 for-in-loop

代码如下:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
                    var error: NSError?
                    let responseDictionary: Dictionary<String, AnyObject> = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: &error) as Dictionary
                    let venuesArray: AnyObject = (responseDictionary as AnyObject).valueForKeyPath("response.venues")

                    for test: AnyObject in venuesArray {
                        println(test)
                    }
                });

我得到的错误是:Type 'AnyObject' does not conform to protocol 'Sequence'

有解决方法吗?

1 个答案:

答案 0 :(得分:2)

问题在于venuesArray循环期望数组类型不是单个对象:

在您的代码中:let venuesArray: AnyObject = //这不是数组,

let venuesArray: AnyObject[] = //这可能是anyObject的数组

相应地尝试实现目标。