-
Notifications
You must be signed in to change notification settings - Fork 0
Home
What?
OCHGen is a tool that uses information available from an Objective-C implementation file to do useful things. Currently the useful thing that is performed is the generation of the corresponding header file, although more features are planned in the future. In order to generate the header file, OCHGen uses both information that any .m file would necessarily have, as well as annotations written by the author of the .m file which are comments in a special form.
Why?
I got fed up with cutting and pasting method prototypes as I was evolving class design, and jumping back and forth between .h and .m files to declare properties. As I am a strong believer of Once and Only Once, I thought the development process of Objective-C code could do with a bit of improvement in this regard.
Usage
Write an Objective-C .m file.
Make annotations in the .m file as necessary – see ‘specs’ for what annotations are available, and how the tool interprets them.
Run header_generator.rb HelloWorld.m and observe the output.
When you decide you want to keep using this, define a ‘run script’ build action in XCode with your source directory as the argument to make OCHGen process all your classes.
Spec
Class-level annotation
Example:
/*@
#import <foundation/foundation.h>state:
NSDictionary* keyPathRegistrationDictionary
*/
Outcome:
Generates import statements and instance variable declarations in the .h file. Content of annotation can be empty. If no class-level annotation found in the .m file, the class is considered out of scope.
Class name and superclass annotation
Example:
implementation KVObserver //
:SomeSuperclass
Outcome:
Generates the interface declaration start line specifying the superclass in the .h file. If no superclass annotation found, defaults to NSObject.
Property
Example:
synthesize calcController; //
(assign,atomic) CalcController*
Outcome:
Generates the instance variable declaration and property declaration in the .h file.
Method prototypes
Example:
-(void) doSomething {
Outcome:
Generates method prototypes in the .h file. No annotation necessary.