discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to initialise an array class inheriting from NSArray?


From: Andreas Heppel
Subject: Re: How to initialise an array class inheriting from NSArray?
Date: Wed, 04 Jun 2003 10:17:40 +0200

On 2003-06-04 03:40:24 +0200 Christopher Culver <crculver@users.sourceforge.net> wrote:

I'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;
}

In addition to what Yen-Ju already said it should be mentioned that the code above would eventually fail anyway. +arrayWithObjects returns an autoreleased array, meaning that the resulting array would be gone sooner or later automatically and your app would blast.

Concerning categories, be aware that adding a category to NSArray would affect _all_ NSArray objects in your app, even those you do not want to use as data sources. This does not automatically mean that categories are bad, but simply keep it in mind.

Andreas


--
Andreas Heppel

Mail: aheppel at web dot de
Home: http://www.andreasheppel.de

Check out Burn.app - the CD burning frontend for GNUstep
http://gsburn.sourceforge.net





reply via email to

[Prev in Thread] Current Thread [Next in Thread]