答案 0 :(得分:0)
我假设您可以使用dict["tasks"]
从字典中获取数组,然后可以对其进行迭代并为每行创建一个新的Task。
for dict in dataArray {
let entity = NSEntityDescription.entity(forEntityName: "Season", in: managedContext)!
let season = Season(entity: entity, insertInto: managedContext)
let seasonDict = dict as! [String: Any]
season.name = seasonDict["name"] as? String
//season.tasks = seasonDict["tasks"] as? NSSet Remove this line
let tasks = dict["tasks"] //Maybe this should be seasonDict?
for taskItem in tasks {
var task = Task(context: managedContext)
task.title = taskItem.title
task.details = taskItem.details
task.parentSeason = season
}
}