Templates for @interface and @implementation files

I’m always checking where I have to put my instance variables and whether I need braces so I just created a simple template that I use to check when necessary.

Interface Template

#import <UIKit/UIKit.h>

@class ClassForwardDeclaration;

@interface MyClass : NSObject  {
    NSString   *myString;  // publicly accessible instance variable
}

@property (nonatomic, strong) IBOutlet UILabel *someLabel;

- (IBAction)someActionMethod:(id)sender; 

@end

Implementation Template

#import "MyClass.h"

#define kPublicDefine @"something public"

@interface MyClass()
@property (nonatomic, strong, readwrite) NSURLRequest *request; // properties private to this class
@end

@implementation MyClass {
     int someNumber; // private instance variable
}

#define kPrivateDefine @"something private"

- (void)viewDidLoad
{

}

@end

More here:
http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocDefiningClasses.html#//apple_ref/doc/uid/TP30001163-CH12-TPXREF126
and a post re private instance variables in the .m file here:
http://stackoverflow.com/questions/10407848/is-this-a-new-way-to-define-private-instance-variables-in-objective-c

Leave a Reply

Your email address will not be published. Required fields are marked *