gpt4 book ai didi

ios - Swift3 错误 : Type 'NSFastEnumerationIterator.Element' (aka 'Any' ) does not conform to protocol 'AnyObject'

转载 作者:搜寻专家 更新时间:2023-11-01 05:53:19 24 4
gpt4 key购买 nike

所以,我正在尝试将我的待办事项列表应用程序更新到 swift 3/iOS 10,但我在更新时遇到了这个错误。我查阅了互联网和 StackOverflow,发现其他人也遇到了这个问题,但那里的解决方案对我没有帮助。这只是一个文件,负责插入核心数据。

这是该文件的代码:

import UIKit
import CoreData

var taskMgr: TaskManager = TaskManager()

struct task {
var name = "not defined"
var desc = "not defined"
}

class TaskManager: NSObject {
var tasks = [task]()
var persistenceHelper: PersistenceHelper = PersistenceHelper()

override init(){

let tempTasks:NSArray = persistenceHelper.list(entity: "Task")
for res:AnyObject in tempTasks{
tasks.append(task(name:res.valueForKey("name")as! String,desc:res.valueForKey("desc") as! String))
}
}


func addTask(name:String, desc: String){

var dicTask: Dictionary<String, String> = Dictionary<String,String>()
dicTask["name"] = name
dicTask["desc"] = desc

if(persistenceHelper.save(entity: "Task", parameters: dicTask)){
tasks.append(task(name: name, desc: desc))
}
}

func removeTask(index:Int){
let value:String = tasks[index].name

if(persistenceHelper.remove(entity: "Task", key: "name", value: value)){
tasks.remove(at: index)
}
}

}

所以它在第 18 行给出了一个错误,它是这样的:

Type 'NSFastEnumerationIterator.Element' (aka 'Any') does not conform to protocol 'AnyObject'

谁能帮帮我?谢谢:)

最佳答案

请像这样更新第 18 行。我希望这对你有用。

  for res:AnyObject in tempTasks as [AnyObject]

关于ios - Swift3 错误 : Type 'NSFastEnumerationIterator.Element' (aka 'Any' ) does not conform to protocol 'AnyObject' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39531613/

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