KCOrderedAccessorFix
KCOrderedAccessorFix copied to clipboard
Question: How are these accessors supposed to be invoked?
The README
states that the following methods are generated, but how on Earth is the user supposed to call them?:
- (void)insertObject:(NSManagedObject *)value in<Key>AtIndex:(NSUInteger)idx;
- (void)removeObjectFrom<Key>AtIndex:(NSUInteger)idx;
- (void)insert<Key>:(NSArray *)value atIndexes:(NSIndexSet *)indexes;
- (void)remove<Key>AtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectIn<Key>AtIndex:(NSUInteger)idx withObject:(NSManagedObject *)value;
- (void)replace<Key>AtIndexes:(NSIndexSet *)indexes with<Key>:(NSArray *)values;
- (void)add<Key>Object:(NSManagedObject *)value;
- (void)remove<Key>Object:(NSManagedObject *)value;
- (void)add<Key>:(NSOrderedSet *)values;
- (void)remove<Key>:(NSOrderedSet *)values;
The IDE nor the compiler will pick these up because they're dynamically generated.
I can only imagine that the intended way to invoke these methods is to use performSelector:
or dispatch_sync()
or some such. These are quite unsafe to call.
I currently maintain positionIndex
field for entities that require some specific ordering. Managing these indices is becoming a bit of a pain and probably doesn't scale well. It may become necessary to introduce an intermediate object. Sadly, KCOrderedAccessorFix
has not been the fix I'd been hoping for.
The definitions are suppose to be generated by Xcode when generating the CoreData classes.
So if I use mogenerator then KCOrderedAccessorFix does absolutely nothing for me then, since mogenerator generates code in a completely different way?
I wouldn't go as far as marking the whole situation helpless just because a simple step is missing.
If mogenerator (I've not looked into it) doesn't generate those accessors, it's probably very simple to extend the framework and generate them, either by writing the logic itself, or calling Apple's generators, then copying the result.
If it were me, I'd probably just generate the classes with Apple's engine, then use a script to rename those files to categories: MyModel (CoreDataGeneratedAccessors)
.