Search code examples
jsonswiftxcodealamofirewordpress-rest-api

Type of expression is ambiguous without more context Alamofire Request Error


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.

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 ..


Solution

  • 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 {
                    
    
             }
    }