简体   繁体   中英

Cannot convert value of type '[String:Any]?' to expected argument type '_?'

The P and R is genericity types

open func route<P,R>(url:URL , param : P? ) -> R?{
    guard let s = url.scheme ,let h = url.host  else{
        #if DEBUG
            print("url error")
        #endif
        return nil
    }

    let urlString = "\(s)://\(h)\(url.path)"


    guard let t = self.urlTaskMap[urlString] as? RoyTaskClosure<P,R> else {

        print("closure unmatched,url -> \(urlString)")

        return nil
    }

    let returnValue = t(param)

    return returnValue
}

And when I invoke the function like

public func viewController(url:URL,param:[String:Any]?) -> RoyProtocol?{
    if let vc = self.route(url: url, param: param){
        return vc
    }
    return nil
}

The Xcode show me a error message

Cannot convert value of type '[String:Any]?' to expected argument type '_?'

God! Can somebody tell me how to fix it?

I got the solution.Replace your method with this

public func viewController(url:URL,param:[String:Any]?) -> RoyProtocol?{
    let vc: RoyProtocol? = self.route(url: url, param: param)
    return vc
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM