Home > Net >  Type of expression is ambiguous without more context Alamofire Request Error
Type of expression is ambiguous without more context Alamofire Request Error

Time:12-01

i am very new to Xcode and trying to fetch data from my WordPress website in SwiftUI using rest api. i have got code from internet , i have installed these pod's

pod 'SwiftyJSON'
pod 'Alamofire'
pod 'SDWebImage'

imported all pods in homeController and using this code to fetch data,, but getting error..

Alamofire.request("\(urlPage)\(page)").responseJSON { response in
          if let data = response.result.value {
             let json2 = JSON(data)
             self.moreDataNum = json2["count"].intValue
             if(self.dataArray?.isEmpty == false){
                self.dataArray.append(contentsOf: json2["posts"].arrayValue)
                self.collectionView.reloadData()

i am getting this error..

open image to see error

please help me ..

CodePudding user response:

You should use Codable framework now to parse the API response

Please read more about Codable here - https://developer.apple.com/documentation/swift/codable

Please should always read documentation of framework/library that you are going to use in your project. Please read more about Alamofire here -

https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#response-handler

CodePudding user response:

if you use latest version of alamofire 5.5.0 then use below code :---

let musicAPI = "https://staging.mywowmemories.com/api/get-background-music"

AF.request(musicAPI, method: .get, parameters: nil, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
          
         if let result = response.value as? NSDictionary {
                

         }
}

  • Related