Re: Subclassing appendFormat: for NSMutableString?
Re: Subclassing appendFormat: for NSMutableString?
- Subject: Re: Subclassing appendFormat: for NSMutableString?
- From: Ben Dougall <email@hidden>
- Date: Sun, 16 May 2004 17:32:57 +0100
On Sunday, May 16, 2004, at 03:22 pm, Dr. H. Nikolaus Schaller wrote:
Hi,
I have tried to subclass NSMutableString and learned that it is a
Class Cluster which can not be subclassed unless I want to add more
internal string representations (which is NOT what I want).
What I want is a class that behaves in some aspects like a
NSMutableString but has additional instance variables. A typical
candidate for subclassing.
Documentation recommends: Write a subclass of NSObject that manages an
NSMutableString as an instance variable and write wrapper methods.
Well, but how do I wrap appendFormat: which is the most important
method I intend to provide by the subclass?
when i first looked at the methods of mutable string i was expecting to
see an appendFormat:arguments: method but there isn't one. there is an
initWithFormat:arguments: method though -- so you could use that
instead (create a whole new string when appendFormat: is called on your
composite object, rather than actually appending, but the end
effect/result will be the same). what the arguments part lets you do is
pass a pointer to a variable argument list, rather than an actual hard
coded variable argument list -- i think.
so the logic would be this: someone calls your composite object
appendFormat: method with a variable argument list as usual. your code,
in that covering appendFormat: method, does whatever is necessary (i'm
not sure what that is -- someone else'll know i'm sure) to convert the
passed variable argument list into a variable argument list pointer
(it's c, not cocoa or obj-c that'll provide the way to do that) and
then call your internal NSMutableString's initWithFormat:arguments:
method using that just made/got variable argument list pointer to
create the wanted string.
so the question is, within a method that has a variable argument list
how do you create the appropriate 'argList' variable in order to call
this?:
- (id)initWithFormat:(NSString *)format arguments:(va_list)argList
then you should be able to use a composite object to do what you want
without subclassing.
_______________________________________________
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.