|
From: | Yen-Ju Chen |
Subject: | Re: How to initialise an array class inheriting from NSArray? |
Date: | Tue, 03 Jun 2003 22:12:14 -0400 |
-arrayWithObjects: is class method, and -init is instance method. Not sure you can mix them together. You probably can try: - (id) init { self = [super initWithObjects: ...]; return self; }and use your NewClass in this way: NewClass *object = [[NewClass alloc] init];
Since you need only two extra methods, category is really more easy. Simply define the extra methods like this: @interface NSArray (ExtraMethod) - (id) extraMethod; @end and implement them as: @implementation NSArray (ExtraMethod) - (id) extraMethod { /* Do something such as */ int count = [self count]; /* ... */ return self; } And use the new category as: #include "YourExtraMethod.h" NSArray *array = [NSArray array]; [array extraMethod]; Hope it help Yen-Ju
From: Christopher Culver <crculver@users.sourceforge.net> To: discuss-gnustep@gnu.org Subject: How to initialise an array class inheriting from NSArray? Date: Wed, 4 Jun 2003 04:40:24 +0300I've got a class that inherits from NSArray, but don't know how to initialise it. Here's how it looks:@implementation NewClass : NSArray. [...] - (id) init { self = [super arrayWithObjects: @"String1", @"String2", nil]; return self; }However, when I compile this, gcc reports that "NSArray doesn't respond to arrayWithObjects". How then am I supposed to initalise this subclass?(And the reason this is a subclass is because I want to use it as a data source for an NSTableView, for which I have to define two extra methods, and this is the only way I know how at the moment. I hear something called "categories" might be useful, but haven't learned about this yet).Christopher Culver _______________________________________________ Discuss-gnustep mailing list Discuss-gnustep@gnu.org http://mail.gnu.org/mailman/listinfo/discuss-gnustep
_________________________________________________________________MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus
[Prev in Thread] | Current Thread | [Next in Thread] |