Re: Subclassing NSString
Re: Subclassing NSString
- Subject: Re: Subclassing NSString
- From: Andreas Monitzer <email@hidden>
- Date: Sat, 16 Jun 2001 11:56:33 +0200
On Saturday, June 16, 2001, at 08:51 , Brendan Younger wrote:
I've been having some difficulties subclassing NSString. Using the code
that follows:
//ModelApp.h
@interface ModelAppObject : NSString
{
ProcessSerialNumber psn;
}
- (void)setPSN:(ProcessSerialNumber*)PSN;
@end
//Other.m
//also, char name[32] is a pascal string in case you were wondering...
[NSMutableArray addObject:[ModelAppObject stringWithCString:&(name[1])
length:name[0]]];
gives this run-time error:
-[ModelAppObject initWithBytes:length:encoding:]: selector not recognized
any ideas as to why?
Because "string objects aren't actual instances of the NSString or
NSMutableString classes but of one of their private subclasses".
And I don't think your objects is really a string when it has a
ProcessSerialNumber. I think you should use the following:
//ModelApp.h
@interface ModelAppObject : NSString
{
ProcessSerialNumber psn;
NSString *string;
}
- (id)initWithString:(NSString*)newString;
- (void)setPSN:(ProcessSerialNumber*)PSN;
- (NSString*)string;
@end
andy
--
Discussion forthcoming.