swift – iOS 12错误:似乎来自与此上下文不同的NSManagedObjectModel

swift – iOS 12错误:似乎来自与此上下文不同的NSManagedObjectModel,第1张

概述在iOS 12模拟器上启动我的应用程序时,我开始出现以下错误.有没有人面临这样的问题? 2018-08-11 21:17:44.440144+0300 CafeManager[4633:128874] [error] error: The fetch request's entity 0x600001f6e940 'TablesTable' appears to be from a differe 在iOS 12模拟器上启动我的应用程序时,我开始出现以下错误.有没有人面临这样的问题?

2018-08-11 21:17:44.440144+0300 CafeManager[4633:128874] [error] error: The fetch request's entity 0x600001f6e940 'tablestable' appears to be from a different NSManagedobjectModel than this context's

我在AppDelegate中定义了全局常量:

let vIEwContext = AppDelegate.vIEwContext

并将它与NSFetchedResultsController一起用于UItableVIEw更新,例如:

import UIKitimport CoreDataclass HistorytablestableVIEwController: FetchedResultstableVIEwController {    //MARK: variables    private var fetchedResultsController: NSFetchedResultsController<tablestable>?    private var currenttable: tablestable?    private var tablenameTextFIEld: UITextFIEld!    //MARK: system functions for vIEw    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        sIDeMenu()        addSyncObserver()    }    overrIDe func vIEwWillAppear(_ animated: Bool) {        updateGUI()    }    // MARK: IBOutlets    @IBOutlet weak var menubutton: UIbarbuttonItem!    // MARK: sIDe menu    private func sIDeMenu() {        if revealVIEwController() != nil {            menubutton.target = revealVIEwController()            menubutton.action = #selector(SWRevealVIEwController.revealToggle(_:))            revealVIEwController().rearVIEwRevealWIDth = 260            vIEw.addGestureRecognizer(self.revealVIEwController().panGestureRecognizer())        }    }    //MARK: functions for table update    private func updateGUI () {        let request : NSFetchRequest<tablestable> = tablestable.fetchRequest()        request.sortDescriptors = [NSSortDescriptor(key: "tablename",ascending: true,selector: #selector(Nsstring.localizedStandardCompare(_:)))]        fetchedResultsController = NSFetchedResultsController<tablestable>(fetchRequest: request,managedobjectContext: vIEwContext,sectionnameKeyPath: nil,cachename: nil)        try? fetchedResultsController?.performFetch()        tableVIEw.reloadData()    }    overrIDe func tableVIEw(_ tableVIEw: UItableVIEw,cellForRowAt indexPath: IndexPath) -> UItableVIEwCell {        let cell = tableVIEw.dequeueReusableCell(withIDentifIEr: "tableCell",for: indexPath) as! HistorytablestableVIEwCell        if let tablestable = fetchedResultsController?.object(at: indexPath) {            cell.tablenameLabel.text = tablestable.tablename            cell.cellDelegate = self            cell.table = tablestable        }        return cell    }    overrIDe func tableVIEw(_ tableVIEw: UItableVIEw,dIDSelectRowAt indexPath: IndexPath) {        let cell = tableVIEw.cellForRow(at: indexPath as IndexPath)        tableVIEw.deselectRow(at: indexPath as IndexPath,animated: true)        currenttable = fetchedResultsController?.object(at: indexPath)        performSegue(withIDentifIEr: "showtableSessions",sender: cell)    }    //MARK: prepare for segue    overrIDe func prepare(for segue: UIStoryboardSegue,sender: Any?) {        if segue.IDentifIEr == "showtableSessions" {            if let tableSessionsTVC = segue.destination as? tableSessionstableVIEwController {                tableSessionsTVC.Title = self.currenttable!.tablename!                tableSessionsTVC.currenttable = self.currenttable!            }        }    }}// MARK: Delegatesextension HistorytablestableVIEwController: HistorytablestableVIEwCellDelegate {    func dIDPresstablesCellbutton(table: tablestable) {        currenttable = table    }}// Common extension for fetchedResultsControllerextension HistorytablestableVIEwController {    overrIDe func numberOfSections(in tableVIEw: UItableVIEw) -> Int {        return fetchedResultsController?.sections?.count ?? 1    }    overrIDe func tableVIEw(_ tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int {        if let sections = fetchedResultsController?.sections,sections.count > 0 {            return sections[section].numberOfObjects        }        else {            return 0        }    }    overrIDe func tableVIEw(_ tableVIEw: UItableVIEw,TitleForheaderInSection section: Int) -> String? {        if let sections = fetchedResultsController?.sections,sections.count > 0 {            return sections[section].name        }        else {            return nil        }    }    overrIDe func sectionIndexTitles(for tableVIEw: UItableVIEw) -> [String]? {        return fetchedResultsController?.sectionIndexTitles    }    overrIDe func tableVIEw(_ tableVIEw: UItableVIEw,sectionForSectionIndexTitle Title: String,at index: Int) -> Int {        return fetchedResultsController?.section(forSectionIndexTitle: Title,at: index) ?? 0    }}// Observer to check that sync was performed to update GUIextension HistorytablestableVIEwController {    private func addSyncObserver () {        NotificationCenter.default.addobserver(forname: Notification.name(rawValue: appDelegate.syncDIDFinishNotification),object: nil,queue: nil) {            [weak self] notification in            dispatchQueue.main.async {                self?.updateGUI()            }        }    }}

同时它看起来像应用程序工作,但没有机会正确测试一切.

我使用CoreData,Seam3框架.

我发现在github上只提到了这个错误,但没有看到解决方案.

解决方法 iOS 12也遇到了这个错误.这就是我最终在我的项目中修复它的方法.这是在Objective C中,而不是Swift,但希望它会让你朝着正确的方向前进.

产生此错误的代码如下所示

// in the init code for my objectNsstring *pathm = [[NSBundle mainBundle] pathForResource:@"mycoredb" ofType:@"momd"];NSURL *momURL = [NSURL fileURLWithPath:pathm];self.model = [[NSManagedobjectModel alloc] initWithContentsOfURL:momURL];// in another method in the objectNSFetchRequest *request = [[NSFetchRequest alloc] init];NSEntityDescription *entity = [[self.model entitIEsByname] objectForKey:@"Model_name"];[request setEntity:entity];

该问题与实体有关.所以我更新了我的代码以反映此页面上的示例:https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreData/FetchingObjects.html

这是我的代码现在的样子

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityname:@"Model_name"];

不再“看起来来自与此上下文不同的NSManagedobjectModel”错误.

总结

以上是内存溢出为你收集整理的swift – iOS 12错误:似乎来自与此上下文不同的NSManagedObjectModel全部内容,希望文章能够帮你解决swift – iOS 12错误:似乎来自与此上下文不同的NSManagedObjectModel所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1003230.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存