• 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
Confusing problems with inheritance in Objective-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Confusing problems with inheritance in Objective-C


  • Subject: Confusing problems with inheritance in Objective-C
  • From: Darren Ford <email@hidden>
  • Date: Tue, 22 Jun 2004 12:31:58 +1000

Hey all,

I've been having some problems trying to implement inheritance using Objective-C (more specifically, attempting to create a class that inherits from NSMutableDictionary).

What I'm finding is that when one of my methods (for example, the 'setDate' function below), that when it attempts to call the super's method, I get the error :-
-setObject:forKey: only defined for abstract class. Define -[MyInheritedDictionaryClass setObject:forKey:]'

Isn't NSMutableDictionary a concrete class (ie. I can instantiate one using alloc/init?)

I've been programming in C++ for many years now, and I think the problem is probably that I haven't fully understood the Obj-C concept of inheritance and I'm trying to use my C++ knowledge to define my class. Can anyone shed any light on why I'm seeing this problem? I've attached my class definitions to the end of the email.

Cheers and thanks -- Darren.

---------- header

@interface MyInheritedDictionaryClass : NSMutableDictionary
- (NSDate *)theDate;
- (void)setTheDate:(NSDate *)newTheDate;
- (NSMutableArray *)theFiles;
- (void)setTheFiles:(NSMutableArray *)newTheFiles;
@end

---------- source

@implementation MyInheritedDictionaryClass

- (id) init
{
return [super init];
}

-(void) dealloc
{
[super dealloc];
}

- (NSDate *)theDate
{
return [super objectForKey:@"date"];
}

- (void)setTheDate:(NSDate *)newTheDate
{
[super setObject:newTheDate forKey:@"date"];
}

- (NSMutableArray *)theFiles
{
return [super objectForKey:@"files"];
}

- (void)setTheFiles:(NSMutableArray *)newTheFiles
{
[super setObject:newTheFiles forKey:@"files"];
}

@end
_______________________________________________
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: Confusing problems with inheritance in Objective-C
      • From: Chris Hanson <email@hidden>
    • Re: Confusing problems with inheritance in Objective-C
      • From: Nick Zitzmann <email@hidden>
    • Re: Confusing problems with inheritance in Objective-C
      • From: Prachi Gauriar <email@hidden>
    • Re: Confusing problems with inheritance in Objective-C
      • From: David Reed <email@hidden>
  • Prev by Date: Re: Multiple declarations and the ID type
  • Next by Date: Re: Confusing problems with inheritance in Objective-C
  • Previous by thread: Re: Cmd+ to be same as cmd=
  • Next by thread: Re: Confusing problems with inheritance in Objective-C
  • Index(es):
    • Date
    • Thread