gpt4 book ai didi

ios - 关于 Swift 中模型结构的可选绑定(bind)的问题

转载 作者:行者123 更新时间:2023-11-28 10:02:46 24 4
gpt4 key购买 nike

我在写代码的时候遇到了这个错误。

Expression pattern of type 'BookArr?' cannot match values of type 'BookArr?'

代码!!

func infiniteScrolling(_ genre: BookArr?, _ indexPath: IndexPath) {
switch genre {
case booksGenre: return callNextBookDefault() //error!!!
}
}

我该如何修复这个错误?

最佳答案

你没有提到函数的返回类型 infiniteScrolling .所以编译器提示你不能设置从 infiniteScrolling 返回任何东西因为您没有设置它的返回类型而起作用。

要么你需要删除return来自 infiniteScrolling方法

func infiniteScrolling(_ genre: BookArr?, _ indexPath: IndexPath) {
switch genre {
case booksGenre: callNextBookDefault()
}
}

或者您需要指定 infiniteScrolling 的返回类型功能。

func infiniteScrolling(_ genre: BookArr?, _ indexPath: IndexPath) -> <ReturnType> {
switch genre {
case booksGenre: return callNextBookDefault()
}
}

callNextBookDefault函数的返回类型应与 <ReturnType> 相同

关于ios - 关于 Swift 中模型结构的可选绑定(bind)的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58637767/

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