Why doesn't the automatically generated subclass NSManagedObject have a β€œright” header?

If I subclass a subclass of NSManagedObject, I see these functions in Business.m implementation files (for example)

None of these features are declared in the Business.h header file. I have to personally add

- (void)addDistrictsObject:(District *)value; - (void)addCategoriesObject:(Category *)value; - (void)addReviewsObject:(Review *)value; 

I wonder why I need to add this ad manually? Why not automatically when I tried to create a SubClass?

Here is the function, by the way:

 - (void)addPromotionsObject:(Promotion *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"Promotions" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"Promotions"] addObject:value]; [self didChangeValueForKey:@"Promotions" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)removePromotionsObject:(Promotion *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"Promotions" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"Promotions"] removeObject:value]; [self didChangeValueForKey:@"Promotions" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)addPromotions:(NSSet *)value { [self willChangeValueForKey:@"Promotions" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; [[self primitiveValueForKey:@"Promotions"] unionSet:value]; [self didChangeValueForKey:@"Promotions" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; } - (void)removePromotions:(NSSet *)value { [self willChangeValueForKey:@"Promotions" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; [[self primitiveValueForKey:@"Promotions"] minusSet:value]; [self didChangeValueForKey:@"Promotions" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; } - (void)addCategoriesObject:(Category *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"Categories" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"Categories"] addObject:value]; [self didChangeValueForKey:@"Categories" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)removeCategoriesObject:(Category *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"Categories" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"Categories"] removeObject:value]; [self didChangeValueForKey:@"Categories" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)addCategories:(NSSet *)value { [self willChangeValueForKey:@"Categories" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; [[self primitiveValueForKey:@"Categories"] unionSet:value]; [self didChangeValueForKey:@"Categories" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; } - (void)removeCategories:(NSSet *)value { [self willChangeValueForKey:@"Categories" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; [[self primitiveValueForKey:@"Categories"] minusSet:value]; [self didChangeValueForKey:@"Categories" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; } - (void)addImagesObject:(Image *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"Images" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"Images"] addObject:value]; [self didChangeValueForKey:@"Images" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)removeImagesObject:(Image *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"Images" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"Images"] removeObject:value]; [self didChangeValueForKey:@"Images" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)addImages:(NSSet *)value { [self willChangeValueForKey:@"Images" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; [[self primitiveValueForKey:@"Images"] unionSet:value]; [self didChangeValueForKey:@"Images" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; } - (void)removeImages:(NSSet *)value { [self willChangeValueForKey:@"Images" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; [[self primitiveValueForKey:@"Images"] minusSet:value]; [self didChangeValueForKey:@"Images" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; } - (void)addReviewsObject:(Review *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"Reviews" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"Reviews"] addObject:value]; [self didChangeValueForKey:@"Reviews" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)removeReviewsObject:(Review *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"Reviews" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"Reviews"] removeObject:value]; [self didChangeValueForKey:@"Reviews" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)addReviews:(NSSet *)value { [self willChangeValueForKey:@"Reviews" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; [[self primitiveValueForKey:@"Reviews"] unionSet:value]; [self didChangeValueForKey:@"Reviews" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; } - (void)removeReviews:(NSSet *)value { [self willChangeValueForKey:@"Reviews" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; [[self primitiveValueForKey:@"Reviews"] minusSet:value]; [self didChangeValueForKey:@"Reviews" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; } - (void)addURLsObject:(URL *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"URLs" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"URLs"] addObject:value]; [self didChangeValueForKey:@"URLs" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)removeURLsObject:(URL *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"URLs" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"URLs"] removeObject:value]; [self didChangeValueForKey:@"URLs" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)addURLs:(NSSet *)value { [self willChangeValueForKey:@"URLs" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; [[self primitiveValueForKey:@"URLs"] unionSet:value]; [self didChangeValueForKey:@"URLs" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; } - (void)removeURLs:(NSSet *)value { [self willChangeValueForKey:@"URLs" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; [[self primitiveValueForKey:@"URLs"] minusSet:value]; [self didChangeValueForKey:@"URLs" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; } - (void)addDistrictsObject:(District *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"Districts" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"Districts"] addObject:value]; [self didChangeValueForKey:@"Districts" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)removeDistrictsObject:(District *)value { NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1]; [self willChangeValueForKey:@"Districts" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [[self primitiveValueForKey:@"Districts"] removeObject:value]; [self didChangeValueForKey:@"Districts" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; [changedObjects release]; } - (void)addDistricts:(NSSet *)value { [self willChangeValueForKey:@"Districts" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; [[self primitiveValueForKey:@"Districts"] unionSet:value]; [self didChangeValueForKey:@"Districts" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value]; } - (void)removeDistricts:(NSSet *)value { [self willChangeValueForKey:@"Districts" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; [[self primitiveValueForKey:@"Districts"] minusSet:value]; [self didChangeValueForKey:@"Districts" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value]; } 
+6
source share
2 answers

Prior to Xcode 4.x, auto-generated code created a header definition for methods. The loss of headers is probably another victim of X4's quality control, unlike Apple.

Headers are really only needed for intellisense or some other human interface tool. The @dynamic preprocessor @dynamic will tell the compiler that methods exist based on naming conventions. At run time, Core Data will validate the class by sending respondsToSelector to the generated objects or using direct key methods.

You can always add them yourself using a small script that runs manually or using the assembly. It's a pain, but apparently the X4's design focused on managing large multi-disciplinary projects, and they threw the ball at some of the old stuff.

+7
source

Interface methods are necessary only for checking the static type and are used only at compile time, if method calls are dynamically generated at run time, then interface method declarations do nothing.

0
source

Source: https://habr.com/ru/post/888205/


All Articles