iosobjective-ccore-datamogenerator

MOGenerator and NSOrderedSet


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?


Solution

  • 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!