• 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
Subclassing NSDictionary...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Subclassing NSDictionary...


  • Subject: Subclassing NSDictionary...
  • From: Alec Carlson <email@hidden>
  • Date: Fri, 26 Apr 2002 16:37:27 -0500

Hopefully, this will be a quick answer by someone. I am trying to subclass
NSMutableDictionary as follows:

@interface foo : NSMutableDictionary {
}
-(id) init;
-(void) setSomeValue:(NSString *)theValue;
@end

and implement it as follows:

@implementation foo
-(id) init
{
self = [super init];
return self;
}

- (void) setSomeValue:(NSString *)theString
{
[self setObject:theString forKey:@"key"];
}
@end

I instantiate the object and test it as follows:
{
foo *test = [[foo alloc] init];

[foo setSomeValue:3];
}

When I execute the [foo setSomeValue:3] line, I get:
2002-04-26 16:28:36.847 TestServer[2797] An uncaught exception was raised
2002-04-26 16:28:36.848 TestServer[2797] *** -setObject:forKey: only defined
for abstract class. Define -[foo setObject:forKey:]!

I tried adding
- (void) setObject:(id)anObject forKey:(id)aKey;

to foo's methods and implement it as follows:
- (void) setObject:(id)anObject forKey:(id)aKey
{
[super setObject:anObject forKey:aKey];
}

but this produces the same exception. If I change super to self, it calls
itself recursively.

I know enough about obj-c to be dangerous. I'm sure there is a simple
answer. Some help would be appreciated.

Thanx -

Alec
-----------------------------------------------------------------------
Time is Short, and the Water Rises
-----------------------------------------------------------------------
_______________________________________________
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: Subclassing NSDictionary...
      • From: Sherm Pendley <email@hidden>
    • Re: Subclassing NSDictionary...
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Customizing NSAlertPanel (newbie question)
  • Next by Date: Re: NSDocument: how to save document as a simple text file
  • Previous by thread: Customizing NSAlertPanel (newbie question)
  • Next by thread: Re: Subclassing NSDictionary...
  • Index(es):
    • Date
    • Thread