Re: NSArray/MutableArray subclass/extension
Re: NSArray/MutableArray subclass/extension
- Subject: Re: NSArray/MutableArray subclass/extension
- From: Ben Dougall <email@hidden>
- Date: Mon, 20 Oct 2003 11:22:13 +0100
On Monday, October 20, 2003, at 01:40 am, Jonathan Jackel wrote:
I'd write a category on NSArray and include your new initWith...
method there. That way the method would be available to all NSArrays
and NSMutableArrays. You can call the built-in init methods from your
method, and return the init-ed objects from your method.
thanks for the reply. yes i did try that but couldn't get it to work. i
had problems with warnings about NSArray not responding to the various
extra NSMutableArray methods - but they were just warnings so maybe
they were fine left. i don't know. i ended up making everything the
NSMutableArray type which got rid of the warnings but also got rid of
any possibility of an NSArray. also i had a problem with when i was
populating the array in the extra init method i got "-count sent to an
uninitialized mutable array object" so there was a problem with
attempting to send messages to an array from within the init method.
i'm sure this was all down to my incompetence, so i'll have another
attempt at categories.
thanks, ben.
On Sunday, October 19, 2003, at 08:21 PM, Ben Dougall wrote:
hiyer,
i'm trying to make, but am not even sure what form it should take, a
single extension/wrapper or something of both the NSMutableArray and
NSArray classes to give my code that uses it a single, very simple
(simple from the use of it point-of-view) initWith method that
returns an appropriate object. the goal is to be able to get back
simply from a single initWith:(id)someThings call an object that has
been appropriately decided on by the class in question and also
populated appropriately - the 'appropriately' decisions based
entirely on someThings that's passed in the int parameter, made by
the class that this question is about.
for example if string points to an NSString instance, and ???? = what
this question is asking about :
???? *x = [[???? alloc] initWith:string];
that'd leave x pointing to the extension/wrapper/whatever. say, in
the above case, because it was a string, the string is split up in a
particular way and the end result makes use of an NSArray. and..
???? *x = [[???? alloc] initWith:anArrayOfThings];
because that was an array passed to the init method the new array
gets populated in a particular way and what's returned makes use of
an NSMutableArray.
the point is, depending on what is passed in initWith i want to have
that method make decisions and be able to return an instance that
contains/wraps/extends either an NSArray or NSMutableArray set up in
various ways, again based on what was passed in initWith.
also the returned object needs to have some extra methods of its own
so can not be just a straight normal array or mutable array.
i've grappled with several things, so far which i haven't had much
luck with. i tried 'composite objects' (which subclass the abstract
class and passes most method calls straight on) as described on the
bottom of apple's class clusters page, and catagories - i'm not
saying i think those two ways are necessarily wrong for this (or
right), i'm just saying i couldn't get either of them to work. any
ideas how that should be done? (i'm very much set on one single init
method that makes decisions and returns all the various types).
thanks, ben.
_______________________________________________
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.
_______________________________________________
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.