返回时Swift数组为空

时间:2016-03-25 12:20:13

标签: arrays swift alamofire

我有以下功能(地址和标题已删除):

    func getChannelEPG(id: String) -> [GlossGuide]{

   var guide = [GlossGuide]()

    Alamofire
        .request(.POST, "http://link.to.api")
        .responseJSON { response in

            if let JSON2 = response.result.value {
                if let responseguide = JSON2["g"]!![id] as! [AnyObject]? {
                    for item in responseguide{
                        if let thisitem = GlossGuide(json: item as! JSON){
                            guide.append(thisitem)
                        }
                    }
                }
                print("Elements1: \(guide.count)")
            }
            print("Elements2: \(guide.count)")
    }
    print("Elements3: \(guide.count)")
    return guide
}

三张照片返回以下内容:

Elements3:0

Elements1:14

元素2:14

为什么元素3(我想要返回的那个)为0,当在此之前阵列中有14个元素时。在我的alamofire请求之前,回报是否以某种方式被调用?

0 个答案:

没有答案
相关问题