• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Subclass of NSMutableArray isn't working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclass of NSMutableArray isn't working


  • Subject: Re: Subclass of NSMutableArray isn't working
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Tue, 9 Mar 2004 22:54:19 -0800

Hello...

First, are you sure that what you really want to do is subclass NSMutableArray? While there is no way for me to know exactly what you plan to use this class for, most of the time you would be better off creating a subclass of NSObject that has an instance variable pointing to an NSMutableArray. In other words:

@interface Graph : NSObject
{
NSMutableArray *data;
/* ... */
}
/* ... */
@end

If the Graph class that you are making is intended to be used by other objects as an Array (in other words external objects are calling the count, addObject:, objectAtIndex:, etc methods directly) then maybe you really do want an NSMutableArray subclass. If you are mainly using the normal Array methods internally (as part of the implementation of the Graph methods) and accessing the Graph object using other methods that you are adding to your class, then you probably are better off creating a sublcass of NSObject which uses an NSMutableArray instance variable.


If you still insist on making an NSMutableArray subclass :) you would want to take a look at the Cocoa Conceptual Topic on class clusters at:

http://developer.apple.com/documentation/Cocoa/Conceptual/Foundation/Concepts/ClassClusters.html

and you can search the list archives for "class cluster" if you still need more info about how to go about making your NSMutableArray subclass after reading that.


Louis


Hi-

I am trying to create a subclass of NSMutableArray called Graph. When I do so and then call any supposedly inherited method (such as -count), I get this runtime error:

-count only defined for abstract class. Define -[Graph count]!

If I modify my instantiation of the object from: Graph *thisGraph = [[Graph alloc]init];
to: Graph *thisGraph = [Graph arrayWithCapacity:1];

the error becomes:

initialization method -initWithCapacity: cannot be sent to an abstract object of class Graph: Create a concrete instance!

In my understanding of abstract classes, they can be subclassed but not instantiated. In this case I cannot subclass it but I can instantiate it.

-Jamie Griffin

"Darmok at Tenagra, Darmok and Gelad on the ocean."
<email@hidden><email@hidden>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Subclass of NSMutableArray isn't working
      • From: Jamie Griffin <email@hidden>
References: 
 >Subclass of NSMutableArray isn't working (From: Jamie Griffin <email@hidden>)

  • Prev by Date: Conversion from an absolute URL to relative
  • Next by Date: Disappearing "e" in number formatter in IB ???
  • Previous by thread: Conversion from an absolute URL to relative
  • Next by thread: Re: Subclass of NSMutableArray isn't working
  • Index(es):
    • Date
    • Thread