通过Alamofire调用API,但存在一些问题

时间:2018-07-23 11:38:46

标签: ios swift alamofire

我正在通过Alamofire调用api,并且正在完美传递请求参数。我已经检查过,但仍然没有得到回应。我收到成功消息,但没有响应数据。下面是我的代码,

let API = "http://siestalaminates.com/admin/index.php/Webservice/getcategorybybrandid"
let subcate = ["brand_id": brandid] as [String:Any]
        Alamofire.request(API, method: .post, parameters: subcate ).responseJSON
            {
                response in
                //printing response
                print(response)
                let result = response.result
                // let obj=result
                if let dict = result.value as? Dictionary<String,AnyObject>{
                    if let subdata = dict["data"]{
                        self.subcatelist = subdata as! [AnyObject]
                        self.subcategory_collection.reloadData()

                    }
                }
                self.activityIndicator.stopAnimating()
        }

动态传递品牌ID ::

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        ///print("==>",cateid[indexPath.row] as NSString)

            let vc = self.storyboard?.instantiateViewController(withIdentifier: "ProductsubcategoryViewController") as! ProductsubcategoryViewController

            vc.brandid = (self.brandid[indexPath.row] as NSString) as String?


            self.present(vc, animated: false, completion: nil)
    }

如果我静态地传递brand_id,那么我会得到响应,但是当我动态传递它时,它会完美传递但不会得到响应。

1 个答案:

答案 0 :(得分:0)

替换下一行

id

使用

   let subcate = ["brand_id": brandid] as [String:Any]

似乎只有一个问题是可选的和必需的值。我认为您对可选链和必需链都不满意。