• 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: only defined for abstract class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: only defined for abstract class


  • Subject: Re: only defined for abstract class
  • From: "Mark Munz (DevList)" <email@hidden>
  • Date: Thu, 6 Oct 2005 09:10:32 -0500


On Oct 6, 2005, at 2:47 AM, Francis Derive wrote:

From what I have read, here I override the 2 inherited "primitive" methods -count and -objectAtIndex:


I'm assuming that the mutable version has an additional primitive that has to be overridden. Unfortunately Apple documentation on Class Clusters isn't great. Specifically, documenting which classes ARE class clusters and what the primitive methods for each are. NSData and NSMutableData documents what primitive methods are, NSArray and NSMutableArray do not.

I would file bugs on the documentation.

The SousClasse's -count can't be so much different than NSMutableArray's and NSArray's -count, but there is a problem here, because I don't get NSMutableArray as [super className] but SousClasse !


- (unsigned) count { NSLog(@"*** count %@", [super className]); return [super count]; }

The concept article makes it clear that you can't call the inherited object for primitive methods. You have to define that either as your own storage type, or the other option is the composite example (where you wrap around the NSMutableArray, in which case you have an embedded NSMutableArray).



And I overrides objectAtIndex:, somehow :


- (id) objectAtIndex:(unsigned) index {
theObject = [super objectAtIndex:index];
if (![[theObject class] isEqual:laClasse]) {
[NSException raise:NSInternalInconsistencyException format:@"*** class name %s of object %@ is not allowed, give it % s", [theObject className], theObject, [laClasse className]];
} else {
return theObject;
}
}

It really sounds like you want a composite object rather than a true subclass.


@interface SousClasse : NSMutableArray
{
    NSMutableArray*    embeddedObject;
}

- (unsigned) count
{
    return [embeddedObject count];
}

- (id) objectAtIndex:(unsigned) index
{
    id theObject = [embeddedObject objectAtIndex:index];
    /* do something special here */
    return theObject;
}

The main is only this :

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSMutableArray *myArray1 = [[NSMutableArray alloc] init];
SousClasse *myArray2 = [[SousClasse alloc] init]; // From the implemented "init", then myArray2 should be of the default class "NSString".


    [myArray1 addObject:@"un"];
    NSLog(@"myArray1 a %d objets", [myArray1 count]);

//[myArray2 addObject:@"deux"];
NSLog(@"myArray2 a %d objets", [myArray2 count]); // count should be zero.


    [pool release];
    return 0;
}


And I believe you'll need to override an additional method for storing the object in the case of sublcassing NSMutableArray. Not sure which method that is, as it isn't documented (as far as I can tell) and I haven't had to do it myself.


Hopefully that helps a bit.

Mark Munz

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: only defined for abstract class
      • From: Francis Derive <email@hidden>
    • Re: only defined for abstract class
      • From: Greg Herlihy <email@hidden>
References: 
 >only defined for abstract class (From: Francis Derive <email@hidden>)
 >Re: only defined for abstract class (From: Pontus Ilbring <email@hidden>)
 >Re: only defined for abstract class (From: Francis Derive <email@hidden>)

  • Prev by Date: Re: only defined for abstract class
  • Next by Date: Re: CoreData - NSManagedObjectContext notifications - Save vs DidChange ?
  • Previous by thread: Re: only defined for abstract class
  • Next by thread: Re: only defined for abstract class
  • Index(es):
    • Date
    • Thread