gpt4 book ai didi

ios - 抓取结果出现在实际抓取之前

转载 作者:行者123 更新时间:2023-11-28 06:07:35 25 4
gpt4 key购买 nike

今天我什么时候在回溯这段代码

  func salesCountForEmployees(_ employee: Employee) -> String {
let fetchRequest: NSFetchRequest<Sale> = NSFetchRequest(entityName: "Sale")
let predicate = NSPredicate(format: "employee == %@", employee)
fetchRequest.predicate = predicate

let context = employee.managedObjectContext!
do {

let results = try context.fetch(fetchRequest)

return "\(results.count)"
} catch let error as NSError {
print("Error: \(error.localizedDescription)")
return "0"
}
}

我感到“惊讶”,因为回溯字段向我显示结果甚至在实际提取执行之前就已提取。 enter image description here

然后在实际的 fetch 执行结果改变之后(当然) enter image description here

也许有人知道为什么会发生这种情况?

最佳答案

results 变量已声明,但未初始化(因为尚未执行提取),因此它指向您的应用程序先前使用的未清除内存字段。当您继续执行程序时,results 变量中的“垃圾”会被有效的获取结果数组覆盖。

所以这并不意味着您在命令执行之前就执行了获取请求。

关于ios - 抓取结果出现在实际抓取之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47793648/

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