Here’s what I’m trying to do:
I want to put away some methods into separate .h and .m files for a better overview of my code.
So basically I have the myViewController which I want to extend with the method myReactionOnAnimationDidEnd: as a category.
So I declared in "myCustomClasses.h" the following to extend it with my desired method:
#import "myViewController.h"
@interface myViewController (myReactionOnAnimationDidEnd)
- (void)myReactionOnAnimationDidEnd:(NSNotification *)aNotification;
@end
The implementation in "myCustomClasses.m" is:
#import "myCustomClasses.h"
#import "myViewController.h"
@implementation myViewController (myReactionOnAnimationDidEnd)
- (void)myReactionOnAnimationDidEnd:(NSNotification *)aNotification {
self.myLabel1.text = @"Test";
}
@end
The Compiler throws a build failed error “Cannot find interface declaration for ‘myViewController'”
So here’s my questions:
-
The first weird thing is, that everything works fine if I do exactly the same for UIViewController instead of myViewController. But since myViewController is a subclass of UIViewController, why shouldn’t it work for myViewController as well(@interface iSnahViewController : UIViewController)?
-
The other weird thing is that the @implementation in “myCustomClasses.m” works just fine if I skip on the @declaration completely. Now how can that be??
Thank you guys!
Any help much appreciated!!
Hans
Now, the funny thing is, that this very same building error comes up even if I create the category with the New File -> ObjC – Category Template. It basically creates the following two files:
in the header file:
#import "myViewController.h"
@interface myViewController (myCategories) //<-- "Cannot find interface declaration for 'myViewController'"
@end
and with the .m file
#import "myViewController+myCategories.h"
@implementation myViewController (myCategories)
@end
And that’s already enough to bring up the error from above.
I finally got it working!
As the building error occured, I was importing the Category-.h File into the primery Class’s .h file:
which lead to the building error from above. This seems to be wrong! So don’t do that.
I still don’t fully understand how the “myViewController” Class gets to know about it’s categories without even having their .h files imported, but as this appears to be a working way of how this is done, I wanted to share with you.
Thanks everybody for helping!!