call [self init] rather than [super init] (and variants where possible) to

ease derived class initialization (all allocation can be done in -init).
Objective-C rocks :)
This commit is contained in:
Bill Currie 2004-02-13 02:51:38 +00:00
parent de567310fb
commit e472364f51
8 changed files with 23 additions and 17 deletions

View file

@ -4,9 +4,9 @@
@implementation Group
- (id) initWithBounds: (Rect)bounds
- (id) init
{
self = [super initWithBounds:bounds];
self = [super init];
views = [[Array alloc] init];
return self;
}
@ -19,6 +19,7 @@
- (View) addView: (View)aView
{
[views addItem:aView];
return aView;
}
- (void) moveTo: (integer)x y:(integer)y

View file

@ -4,7 +4,7 @@
- (id) initWithComponents: (integer)_x : (integer)_y
{
self = [super init];
self = [self init];
x = _x;
y = _y;
return self;
@ -12,7 +12,7 @@
- (id) initWithPoint: (Point) aPoint
{
self = [super init];
self = [self init];
if (!self || !aPoint)
return NIL;

View file

@ -7,7 +7,7 @@
- (id) initWithComponents: (integer)x : (integer)y : (integer)w : (integer)h
{
self = [super init];
self = [self init];
origin = [[Size alloc] initWithComponents: x : y];
size = [[Size alloc] initWithComponents: w : h];
return self;
@ -15,7 +15,7 @@
- (id) initWithOrigin: (Point)anOrigin size: (Size)aSize
{
self = [super init];
self = [self init];
if (!self || !anOrigin || !aSize)
return NIL;
@ -28,7 +28,7 @@
- (id) initWithRect: (Rect)aRect
{
self = [super init];
self = [self init];
if (!self || !aRect)
return NIL;

View file

@ -4,7 +4,7 @@
- (id) initWithComponents: (integer)w : (integer)h
{
self = [super init];
self = [self init];
width = w;
height = h;
return self;
@ -12,7 +12,7 @@
- (id) initWithSize: (Size)aSize
{
self = [super init];
self = [self init];
if (!self || !aSize)
return NIL;

View file

@ -7,7 +7,7 @@
- (id) initWithBounds: (Rect)aRect size: (integer) aSize
{
self = [super initWithBounds:aRect];
self = [self initWithBounds:aRect];
dir = ylen > xlen;
size = aSize;
index = 0;

View file

@ -3,6 +3,17 @@
#include "draw.h"
@implementation Text
- (id) init
{
text = str_new ();
return self;
}
- (void) dealloc
{
str_free (text);
}
- (id) initWithBounds: (Rect)aRect
{
return [self initWithBounds:aRect text:""];
@ -11,16 +22,10 @@
- (id) initWithBounds: (Rect)aRect text:(string)str
{
self = [super initWithBounds:aRect];
text = str_new ();
str_copy (text, str);
return self;
}
- (void) dealloc
{
str_free (text);
}
- (void) setText: (string)str
{
str_copy (text, str);

View file

@ -7,6 +7,7 @@
- (id) initWithComponents: (integer)x : (integer)y : (integer)w : (integer)h
{
self = [self init];
xpos = xabs = x;
ypos = yabs = y;
xlen = w;

View file

@ -9,7 +9,6 @@
{
Array views;
}
- (id) initWithBounds: (Rect)bounds;
- (void) dealloc;
- (View) addView: (View)aView;
- (void) moveTo: (integer)x y:(integer)y;