2

I have come across an issue, while refactoring some code. I have implemented MOGenerator for my project. However, some of my relationships are ordered, which by default implementation would result in creating 8 different accessory methods for CRUD operations. But MOGenerator doesn't seem to generate those methods at all, but instead provides with default unordered accessory methods.

As an example, this would be generated, if MOGenerator is not used:

- (void)insertObject:(CustomModel *)value inCustomModelAtIndex:(NSUInteger)idx;
- (void)removeObjectFromCustomModelAtIndex:(NSUInteger)idx;
- (void)insertCustomModel:(NSArray *)value atIndexes:(NSIndexSet *)indexes;
- (void)removeCustomModelAtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectInCustomModelAtIndex:(NSUInteger)idx withObject:(CustomModel *)value;
- (void)replaceCustomModelAtIndexes:(NSIndexSet *)indexes withCustomModel:(NSArray *)values;
- (void)addCustomModelObject:(CustomModel *)value;
- (void)removeCustomModelObject:(CustomModel *)value;
- (void)addCustomModel:(NSOrderedSet *)values;
- (void)removeCustomModel:(NSOrderedSet *)values;

This is what MOGenerator generates instead:

- (void)addCustomModel:(NSOrderedSet*)value_;
- (void)removeCustomModel:(NSOrderedSet*)value_;
- (void)addCustomModelObject:(CustomModel*)value_;
- (void)removeCustomModelObject:(CustomModel*)value_;

Has anyone run into this before?

Mick MacCallum
  • 124,539
  • 40
  • 277
  • 276

1 Answers1

2

I have found a solution on my own. Instead of using accessory methods, mogenerator provides you with customModelSet method. Interesting enough,

- (void)addCustomModel:(NSOrderedSet*)value_;
- (void)removeCustomModel:(NSOrderedSet*)value_;
- (void)addCustomModelObject:(CustomModel*)value_;
- (void)removeCustomModelObject:(CustomModel*)value_;

these methods are broken and will raise following exception :

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

In addition, I would like to point out that I have tested it on my own with a really basic example. If anyone has any comments or updates, please feel free to add to this post.

Cheers!

  • seems a long-standing Apple bug: http://stackoverflow.com/questions/7385439/exception-thrown-in-nsorderedset-generated-accessors – IlDan Nov 01 '13 at 15:58