![](/img/trans.png)
[英]Cannot convert value of type '[String : Any]' to expected argument type 'String'
[英]Cannot convert value of type 'String?.Type' to expected argument type 'String?'
我在聲明var updater的標題中遇到了錯誤。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? ProductViewController,
let index = tableViewProducts.indexPathForSelectedRow?.row {
// Check whether postData array count is greater than index
let updaterId = postData.count > index ? postData[index] : ""
// Initialize "productsList" instance and assign the id value and sent this object to next view controller
var updater = productsList(id: String?, p_name: String?, image: String?, audio: String?)
updater.id = updaterId
destination.updater = updater
這是我的產品清單VC:
進口基金會
class productsList {
let id: String?
let p_name: String?
let image: String?
let audio: String?
init(id: String?, p_name: String?, image: String?, audio: String?) {
self.id = id
self.p_name = p_name
self.image = image
self.audio = audio
}
}
您必須將字符串值(或nil
)作為參數而不是類型String?
傳遞String?
,這就是錯誤的意思。
更換
var updater = productsList(id: String?, p_name: String?, image: String?, audio: String?)
updater.id = updaterId
與
let updater = productsList(id: updaterId, p_name: nil, image: nil, audio: nil)
並請遵循類名以大寫字母開頭的命名約定。
這行引起了問題
var updater = productsList(id: String?, p_name: String?, image: String?, audio: String?)
當您初始化對象(即“ ProductList”)時,必須傳遞文件名“ id”,“ p_name”,“ image”和“ audio”的實際值。
現在,您正在發送“字符串?” ,這是參數的類型,您的函數需要該參數的值。
所以改變它像
var updater = productsList(id: ID_OF_PRODUCT, p_name: NAMEOFPRODUCT, image: URLTOIMAGE/IMAGE, audio: AUDIOURL)
用這個
var updater = productsList(id: updaterId, p_name: nil, image: nil, audio: nil)
代替
var updater = productsList(id: String?, p_name: String?, image: String?, audio: String?)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.