当我使用互联网加载我的应用程序然后进入飞行模式我可以加载保存到coreData的帖子。但是,如果我已经在飞机模式下装载我的飞机,我就会在这条线上撞车:
let results = try moc.fetch(fetchRequest)
来自这个功能:
func loadImages(_ fetched:@escaping (_ images:[FullRes]?) -> Void) {
saveQueue.async() {
let context = self.getContext()
guard let moc = context else {
return
}
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = FullRes.fetchRequest()
//let request: NSFetchRequest<NSFetchRequestResult> = FullRes.fetchRequest()
//let fetchRequest = NSFetchRequest(entityName: "FullRes")//NSFetchRequest(entityName: "FullRes")
do {
let results = try moc.fetch(fetchRequest)
let imageData = results as? [FullRes]
DispatchQueue.main.async() {
fetched(imageData)
}
} catch let error as NSError {
print("Could not fetch \(error), \(error.userInfo)")
return
}
}
}
它给了我这样的信息:
由于未捕获的异常终止应用程序&#39; NSInvalidArgumentException&#39;,原因:&#39; executeFetchRequest:错误:不是有效的NSFetchRequest。&#39;
不确定为什么会发生这种情况......有什么想法吗?
答案 0 :(得分:1)
我把它修好了
if Reachability.isConnectedToNetwork() == true {
}
在ViewDidload中的loadPosts()函数周围,因为它从AppDelegate调用方法!
花了我几个小时;)