简体   繁体   English

iOS9设备上的Swift3 CoreData崩溃

[英]Swift3 CoreData crash on iOS9 device

I have CoreData app that is perfectly working on iOS10, written in Swift3, supporting iOS 8.4 and above. 我有完全在iOS10上运行的CoreData应用程序,用Swift3编写,支持iOS 8.4及更高版本。

When I try to run it on iOS 9.3.5 I'm getting error: 当我尝试在iOS 9.3.5上运行它时,我收到错误:

2016-10-07 17:47:20.596 FormApp[710:179733] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSSet intersectsSet:]: set argument is not an NSSet'

crashing on line: 在线崩溃:

form.addToOpenQuestions(openQuestion)

I have added @objc() to managed object classes. 我已将@objc()添加到托管对象类。 Then I'm getting new error: 然后我收到了新的错误:

CoreData: warning: Unable to load class named 'FormApp.Form' for entity 'Form'.  Class not found, using default NSManagedObject instead.

It is happening on line: 它正在线上发生:

let form = NSEntityDescription.insertNewObject(forEntityName: "Form", into: managedObjectContext) as! Form

My config: 我的配置:

enity的设置

类

模型

属性扩展

All classes were generated by Xcode. 所有类都是由Xcode生成的。 I have tried deleting Module and all configurations. 我试过删除模块和所有配置。 Anyone have idea how to make it work? 任何人都知道如何使它工作?

For some reason NSSet is expected, but your NSManagedObject code has NSOrderedSet, which is a subclass of NSObject. 由于某种原因,NSSet是预期的,但您的NSManagedObject代码具有NSOrderedSet,它是NSObject的子类。 Try to remove "Arrangment: Ordered" checkmark in your core data model and refactor those relationships to NSSet. 尝试删除核心数据模型中的“Arrangment:Ordered”复选标记,并将这些关系重构为NSSet。 Not sure why this happens in iOS 10 but not in iOS 9 though. 不知道为什么在iOS 10中会发生这种情况,但在iOS 9中却没有。

PS Perhaps you should reconsider your Core Data model? PS也许你应该重新考虑你的核心数据模型? It looks like your Open/Closed questions are going to change their status. 看起来你的开放/封闭问题会改变他们的状态。 If so, I would recommend to make one Question entity with closed bool or status int. 如果是这样,我建议使用closed bool或status int制作一个Question实体。

I was having the same issue with iOS 9.3 我遇到了与iOS 9.3相同的问题

The issue was same as mention by @alex above and i have solve as below 问题与@alex上面提到的相同,我已解决如下问题

if #available(iOS 11.0, *) {
        // use iOS 11-only feature
        YOUR_CLASS.insertIntoClosedQuestion(YOUR_OBJECT, at: index)
    } else {
        // handle older versions
        let orderset:NSMutableOrderedSet = Form.closeQuestion as! NSMutableOrderedSet
        orderset.insert(YOUR_OBJECT, at: index)
        YOUR_CLASS.addToClosedQuestion(orderset)
    }

Hope it will helpful to others. 希望它对其他人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM