Created
December 20, 2009 16:08
-
-
Save sukima/260541 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SimpleController.h | |
#import <Foundation/Foundation.h> | |
#import "Polygon.h" | |
@interface SimpleController : NSObject { | |
Polygon *myPolyObject; | |
} | |
- (void)testPassingVarToViewObject; | |
- (void)testAnotherWayPassingVarToViewObject; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SimpleView.h | |
#import <Foundation/Foundation.h> | |
#import "Polygon.h" | |
@interface SimpleView : NSObject { | |
Polygon *viewPolygon; | |
} | |
@property (nonatomic, retain) Polygon *viewPolygon; | |
- (id)initWithPolygon:(Polygon *)polygon; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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