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

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.


  • Follow-Ups:
    • Re: Subclassing NSString
      • From: Ali Ozer <email@hidden>
References: 
 >Subclassing NSString (From: Brendan Younger <email@hidden>)

  • Prev by Date: Re: Networking
  • Next by Date: Trouble with NSTimer
  • Previous by thread: Subclassing NSString
  • Next by thread: Re: Subclassing NSString
  • Index(es):
    • Date
    • Thread