• 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: NSArray operator implementing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArray operator implementing


  • Subject: Re: NSArray operator implementing
  • From: mmalcolm crawford <email@hidden>
  • Date: Sat, 27 Nov 2004 11:52:29 -0800


On Nov 27, 2004, at 9:25 AM, Cornelius Jaeger wrote:
so NSArray receive's an @ in it's valueForKeyPath and tries to find an internal method to resolve it? no need to register an observer?

Correct. Although I'm not sure if this is officially supported at the moment. I know there was a discussion about it somewhere -- Scott?

thx for the great code.

Cheers, although looking at it again, and doing a quick experiment, it's not as efficient as it might be. If you're using this as a keypath it might get called often... The following implementation is a little more complicated, but seems (after a very quick test, YMMV) to be at least three times faster (sometimes much more than that).
[ Which is more elegant, recursion or polymorphism? -- you decide! :-) ]


mmalc



@implementation NSArray (Flattened)


- (NSArray *)flattened
{
SEL aSelector = @selector(addToArray:);
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[self count]];

[self makeObjectsPerformSelector:aSelector withObject:array];

return array;
}


- (void)addToArray:(NSMutableArray *)array
{
	SEL aSelector = @selector(addToArray:);
	[self makeObjectsPerformSelector:aSelector withObject:array];
}

@end


@implementation NSObject (Flattened)

- (void)addToArray:(NSMutableArray *)array
{
	[array addObject:self];
}

@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSArray operator implementing
      • From: Steven Kramer <email@hidden>
References: 
 >NSArray operator implementing (From: Cornelius Jaeger <email@hidden>)
 >Re: NSArray operator implementing (From: Steven Kramer <email@hidden>)
 >Re: NSArray operator implementing (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: NSObject hierarchy browser
  • Next by Date: Re: [NSTableView reloadData] doesn't seem to work
  • Previous by thread: Re: NSArray operator implementing
  • Next by thread: Re: NSArray operator implementing
  • Index(es):
    • Date
    • Thread