我正在尝试将 JSON 数据附加到数组。在循环时它不断推送错误,“无法调用初始化程序以类型为参数(id:JSON,标题:JSON,详细信息:String,ImageURL:String)来键入'item''
'Item' 初始值设定项如下所示: 导入 UIKit
class Item: NSObject {
var id: String, title: String, detail: String, imageURL: String
init(id: String, title: String, detail: String, imageURL: String) {
self.id = id
self.title = title
self.detail = detail
self.imageURL = imageURL
}
}
最佳答案
你的构造函数期望得到String
并且你正在发送JSON
我猜你正在使用 SwiftyJSON
因此将其编辑为
id : result[i]["id"].stringValue
title : result[i]["title"].stringValue
如果您不使用 SwiftJSON 将其转换为字符串
result[i]["id"] as! String //warning, this is not safe and better with if let
关于ios - 无法为类型 'item' Swift iOS 调用初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32164993/