3

I have CoreData app that is perfectly working on iOS10, written in Swift3, supporting iOS 8.4 and above.

When I try to run it on iOS 9.3.5 I'm getting error:

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. 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:

Settings of enity

Class

Model

Properties extension

All classes were generated by Xcode. I have tried deleting Module and all configurations. Anyone have idea how to make it work?

Prettygeek
  • 2,461
  • 3
  • 22
  • 44
  • Can you set an Exception breakpoint and show the exact line where the app crashes? Select breakpoints tab in xCode -> "+" button in the bottom left corner -> Exception Breakpoint. Also please show Form+CoreDataProperties.swift file – alexburtnik Oct 07 '16 at 15:58
  • @alex Done. Added screen and lines – Prettygeek Oct 07 '16 at 16:08
  • Do you have Arrangment: Ordered checkmark in your core data model? For some reason it is expecting NSSet, but your NSManagedObject code has NSOrderedSet, which is a subclass of NSObject. Try to remove that checkmark and refactor those relationships to NSSet – alexburtnik Oct 07 '16 at 16:17
  • @alex make it as Your answer. Works. Why it is working on iOS10 and not on iOS9? They make NSOrderedSet subclass of NSSet in this new version or what? – Prettygeek Oct 07 '16 at 16:27

2 Answers2

4

For some reason NSSet is expected, but your NSManagedObject code has NSOrderedSet, which is a subclass of NSObject. Try to remove "Arrangment: Ordered" checkmark in your core data model and refactor those relationships to NSSet. Not sure why this happens in iOS 10 but not in iOS 9 though.

P.S. Perhaps you should reconsider your Core Data model? 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.

alexburtnik
  • 7,661
  • 4
  • 32
  • 70
0

I was having the same issue with iOS 9.3

The issue was same as mention by @alex above and i have solve as below

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.

Wasim Malek
  • 123
  • 7