Skip to content

Instantly share code, notes, and snippets.

@sukima
Created December 20, 2009 16:08
Show Gist options
  • Save sukima/260541 to your computer and use it in GitHub Desktop.
Save sukima/260541 to your computer and use it in GitHub Desktop.
// SimpleController.h
#import <Foundation/Foundation.h>
#import "Polygon.h"
@interface SimpleController : NSObject {
Polygon *myPolyObject;
}
- (void)testPassingVarToViewObject;
- (void)testAnotherWayPassingVarToViewObject;
@end
// SimpleController.m
#import "SimpleController.h"
#import "SimpleView.h"
@implementation SimpleController
- (id)init;
{
if ( (self = [super init]) == nil )
return nil;
myPolyObject = [[Polygon alloc] init];
return self;
}
- (void)dealloc;
{
[super dealloc];
[myPolyObject release];
}
- (void)testPassingVarToViewObject;
{
SimpleView *myView = [[SimpleView alloc] init];
myView.viewPolygon = myPolyObject;
// Do something
// [myView show];
[myView release];
}
- (void)testAnotherWayPassingVarToViewObject;
{
SimpleView *myView = [[SimpleView alloc] initWithPolygon:myPolyObject];
// Do something
// [myView show];
[myView release];
}
@end
// SimpleView.h
#import <Foundation/Foundation.h>
#import "Polygon.h"
@interface SimpleView : NSObject {
Polygon *viewPolygon;
}
@property (nonatomic, retain) Polygon *viewPolygon;
- (id)initWithPolygon:(Polygon *)polygon;
@end
// SimpleView.m
#import "SimpleView.h"
@implementation SimpleView
@synthesize viewPolygon;
// The synthesize above creates a setter and getter for the viewPolygon variable.
// When an object is assigned using these it handles the memory retain automatcally.
- (id)initWithPolygon:(Polygon *)polygon;
{
if ( (self = [super init]) == nil )
return nil;
self.viewPolygon = polygon;
return self;
}
- (void)dealloc;
{
[super dealloc];
[viewPolygon release];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment