gpt4 book ai didi

ios - 从 NSManagedObject 中的 for 循环获取索引

转载 作者:行者123 更新时间:2023-11-28 09:34:20 33 4
gpt4 key购买 nike

我试图在 [NSManagedObject] 中循环时从 for 循环获取索引 我尝试了下面的代码。任何人都知道如何获得它。

错误:键入“[NSManagedObject]?”不符合协议(protocol)“SequenceType”

    for (index, item) in RestaurantQuestions.all() {

print(index) // should print index
//Doing my stuff

}

有什么办法吗?

最佳答案

可能是因为可选类型。尝试摆脱这样的选项:

if let questions = RestaurantQuestions.all() {
for (index, item) in questions.enumerate() {
print(index) // should print index
//Doing my stuff
}
}

关于ios - 从 NSManagedObject 中的 for 循环获取索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37274568/

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