![](/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.