Advitiya Jadhav
Advitiya Jadhav

Reputation: 11

completion error: "Type of expression is ambiguous without more context"?

I am getting a "Type of expression is ambiguous without more context" error and I don't know why! Please help me out so the code will work again plz!

whole code:

class GarbageService{
    let garbageBaseURL : URL?
    init(){
        garbageBaseURL = URL(string : "http://localhost:5000/garbages/findstreets?")
    }
    func getGarbageSchedule(street : String,completion: @escaping (GarbageModel?) -> Void)
    {
        if let garbageURL = URL(string:"\(street)",relativeTo: garbageBaseURL!){
            let clientApi = networkManager(url : garbageURL)
            clientApi.DownloadJSONFromURL{
                (jsonDictionary) in
                print(jsonDictionary as? [String : Any])
                //TODO Parse JSON Object into weather object
                if let garbageDataDictionary = jsonDictionary?["STREETS"] as? [String:Any]{
                    let garbageData = GarbageModel(garbageDictionary: garbageDataDictionary)
                    completion(garbageData)
                }
                else{
                    completion(nil)
                }
            }
        }
    }
}
let garbageService = GarbageService()

garbageService.getGarbageSchedule(street: "HATHAWAY DR",completion: (GarbageModel?) -> Void){
    {(garbageData) in
        print("STREETS: "+String(format:"%s",garbageData?.street as! CVarArg))
    }
}

snippet giving error:

let garbageService = GarbageService()

garbageService.getGarbageSchedule(street: "HATHAWAY DR",completion: (GarbageModel?) -> Void){
    {(garbageData) in
        print("STREETS: "+String(format:"%s",garbageData?.street as! CVarArg))
    }
}

it really bugging me out

Upvotes: 0

Views: 654

Answers (1)

vadian
vadian

Reputation: 285180

Assuming street is String both String(format and the type cast are not needed and will crash if an error occurs.

And there are too many braces, remove the inner pair of braces

garbageService.getGarbageSchedule(street: "HATHAWAY DR") { garbageData in
     print("STREETS: " + garbageData?.street ?? "An error occurred")
}

The format specifier %s is wrong anyway. The specifier for a Swift String is %@

Upvotes: 0

Related Questions