Answer the question
In order to leave comments, you need to log in
Breaking down a large class into categories in objective-c?
There is a PlayerViewController class with a large number of methods, I want to break it into categories, but I don’t understand how to do it so that by connecting PlayerViewController.h methods from all its categories are available.
As tried:
I create category Timer.
//
// PlayerViewController+Timer.h
//
@interface PlayerViewController (Timer)
- (void)testMethod;
@end
//
//PlayerViewController+Timer.m
//
#import "PlayerViewController.h"
#import "PlayerViewController+Timer.h"
@implementation PlayerViewController (Timer)
- (void) testMethod
{
NSLog(@"test");
}
@end
//
// PlayerViewController.h
//
#import <Foundation/Foundation.h>
#import "PlayerViewController+Timer.h"
@interface PlayerViewController : UIViewController
@end
//
// PlayerViewController.m
//
#import "PlayerViewController.h"
@implementation PlayerViewController
- (void)viewDidLoad
{
[self testMethod];
}
@end
/Users/user/Desktop/Projects/SplitClass/PlayerViewController+Timer.h:5:12: Cannot define category for undefined class 'PlayerViewController'
/Users/user/Desktop/Projects/SplitClass/SplitClass/PlayerViewController.m:11:11: No visible @interface for 'PlayerViewController' declares the selector 'testMethod'
Answer the question
In order to leave comments, you need to log in
The first error is that the PlayerViewController is not defined at the time the category is declared. The second follows from the first - the category is not declared, which means there is no method.
If you really want to import just one header for all categories, then my solution is this:
File PlayerViewControllerMain.h : main declarations (without categories)
PlayerViewController + {Category1|Category2|...} .h files : category declarations, each imports PlayerViewControllerMain. h
File PlayerViewController.h : includes all of the above files for easy access to all categories at once
Files PlayerViewController+{Category1|Category2|...}.h: category declarations, each import PlayerViewControllerMain.h
IMHO it is still useful to try AppCode (http://www.jetbrains.com/objc/), it justifies its cost by 146%. For starters, you can try EAP, and there it won’t be long before the sale.
A separate plus can be considered the uniformity of this ide for different platforms - java, php, objc, html / css - almost the same hotkeys and appearance are everywhere, for me it's important.
If you dig a little deeper and study its capabilities, then it can help a lot and “write” (generate) a lot of code for the developer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question