• 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
NSMutableArray subclass (alternatives?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSMutableArray subclass (alternatives?)


  • Subject: NSMutableArray subclass (alternatives?)
  • From: Andrew Merenbach <email@hidden>
  • Date: Mon, 7 Jul 2003 12:18:35 -0700

I've searched the archives and read Apple's docs, but cannot discern the best answer for my particular situation.

I have an outline view that contains nodes, all of the same class, that can have children. I have for this purpose subclassed NSMutableArray to add a title variable, a sorting boolean, a regular mutable array (not of my subclass) to contain the actual children, and a weak link to the parent.

I overrode the primitives of NSMutableArray and NSArray, and all appears well from the logistics side--I can in my program now use all of the foundation array methods to access the children of any particular node. The trouble comes when I wish to copy to a pasteboard; although I have overridden initWithCoder:, encodeWithCoder:, and classForCoder, I receive the following error when data is decoded from the pasteboard:

*** initialization method -initWithObjects:count: cannot be sent to an abstract object of class NPEntry: Create a concrete instance!

The line that causes the error appears to be the call to super's implementation of initWithCoder:

- (id)initWithCoder:(NSCoder *)decoder {
NSLog(@"decoding %@",decoder);
self = [super initWithCoder:decoder];
.............

1. Is a mutable-array subclass the best idea for this? Although a composite object could in theory work just as well, I would for instance not have access to all of the foundation array methods that could be quite useful in my data management.
(As a second idea, would a category prove better? I could redirect title: and parent: methods to access, say, the first and/or last objects, respectively, of an array, thus eliminating the need for a subclass; although this might prove more convoluted.)

2. From reading the archives, I am under the impression that my error is the result of sending initWithObjects:count: to the class itself. Why might the call to NSMutableArray's initWithCoder: cause the error above?

Take care,
Andrew
_______________________________________________
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: NSMutableArray subclass (alternatives?)
      • From: Chris Hanson <email@hidden>
    • Re: NSMutableArray subclass (alternatives?)
      • From: Ben Dougall <email@hidden>
  • Prev by Date: Re: NSHTTPURLResponse
  • Next by Date: Re: How to pause another application or even thread
  • Previous by thread: Re: Setting the origin of a GC and Text
  • Next by thread: Re: NSMutableArray subclass (alternatives?)
  • Index(es):
    • Date
    • Thread