簡體   English   中英

無法轉換類型[[String:Any]? 到預期的參數類型“ _?”

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

P和R是通用類型

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
}

當我像

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

Xcode向我顯示錯誤消息

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

神! 有人可以告訴我如何解決嗎?

我找到了解決方案。用這個替換您的方法

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM