gpt4 book ai didi

ios - swift 4 : Cannot assign value of type '[X]' to type '[VC.X]'

转载 作者:行者123 更新时间:2023-11-28 15:00:50 25 4
gpt4 key购买 nike

如何消除这个编译器错误?如果我在函数内声明项目,一切正常。

class VC: UIViewController {
struct X: Decodable {
let id: String
let name: String
let url: String
}
var items = [X]()

//-----------------------------

func somefunc() {
do {
// the error is here:
self.items = try JSONDecoder().decode([X].self, from: data) <<<<<<<<<<< Compile error is here
}
catch let err {
}
}
} // class VC

最佳答案

应该可以工作(我试过了,没有编译器错误),但是,也许您已经有一些其他同名的类/结构。尝试使用它来确定:

self.items = try JSONDecoder().decode([VC.X].self, from: data) 

关于ios - swift 4 : Cannot assign value of type '[X]' to type '[VC.X]' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48927298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com