rentzsch/mogenerator

Can't add object to ordered set

pip8786 opened this issue · 17 comments

My VectorLayer object has an ordered to-many relationship to VectorStroke named strokes. I cannot seem to add a VectorStroke to my VectorLayer without it crashing.

I've tried adding a VectorStroke to the VectorLayer directly with the following results:
[vectorLayer addStrokesObject:vectorStroke];

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSSet intersectsSet:]: set argument is not an NSSet'

And I've tried using the strokesSet property and got the following results:
[vectorLayer.strokesSet addObject:vectorStroke];

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSManagedObjects of entity 'VectorLayer' do not support -mutableSetValueForKey: for the property 'strokes''

Am I doing something wrong or is this a bug?

#66

I think this commit would help my issue but I don't see how to replace the machine.m files from an installed mogen. How do I do this?

Yes that looks like it would work. You can use a command-line argument to point to your own set of files, or you can replace the ones in Library/Application Support/mogenerator (although I wouldn't suggest that).

Sorry, I missed I that I haven't shipped this fix yet. Will do so soonish.

This issue should still be open, it's not 100% fixed.

You can use the mutableOrderedSet accessory and manipulate the set yourself now but you still cannot use the addObject accessors as it still causes a crash.

I'm not sure how much this is a mogenerator vs a Core Data bug.

@robertjpayne Thanks for the alert. Can you add a repro for this bug to /test?

Any update on this one? The CoreData bug is still there :( Would be ideal if mogen would create a working wrapper. (maybe with a command line toggle?)

http://stackoverflow.com/questions/7385439/exception-thrown-in-nsorderedset-generated-accessors

@batkuip I'd welcome a patch that generated a working wrapper for ordered sets. @robertjpayne makes it sound like using mutableOrderedSet should work.

No need for a command-line toggle, since this would make an otherwise totally-broken piece of Core Data functional.

Actually turns out the patch is already in, just not released. See commit e11ffaf

@batkuip thanks for the tip, I'll see if it actually works.

Cheers. It's not entirely complete as it's missing the insertObject:atIndex methods (atleast that's what the xcode automatically generates in the .h file). Those methods are trickier to implement because the mutableset accessor uses mutableSetValueForKey which seems to call the insertObject:atIndex internally causing it loop forever.

@batkuip thanks for looking into this

Just noticed @batkuip comments.. pull request for this code may have been premature.

I'm going to do more testing and see...

I think I've got a working solution for this. Please checkout the referenced pull request. : D

What's the workaround to this at the minute?

Is this the same issue as this crash, using the pre-1.28 Swift template with an ordered set's inverse relationship?

self.willAccessValueForKey("categoryForItem") <<< EXC_BAD_ACCESS code=2

The PR for this was merged a while ago. If there are any remnants, please open a new issue and we'll work it out.