• 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: Not documented: NSArray responds to -allObjects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Not documented: NSArray responds to -allObjects


  • Subject: Re: Not documented: NSArray responds to -allObjects
  • From: Charles Srstka <email@hidden>
  • Date: Thu, 24 Oct 2013 15:38:39 -0500

On Oct 24, 2013, at 9:19 AM, Jerry Krinock <email@hidden> wrote:

> Starting somewhere after OS X 10.6, NSArray instances respond to the NSSet method -allObjects.  I can’t find any documentation of this.  Also, it is not declared in the header NSArray.h
>
> Although it does what you’d expect, returning a copy of self, this can lead to some interesting bugs, particularly when running in 10.6 after testing in a current system :(   And in some cases one may want to reconsider the usual strategy of preferring -respondsToSelector: instead of -isKindOfClass: for introspection.

That is precisely why I dislike the -respondsToSelector: approach. You never know if you might accidentally call some undocumented method that you were unaware some class had. Either -isKindOfClass: or making a protocol containing -allObjects and making NSSet and other methods conform to it via categories seems safer in general.

On Oct 24, 2013, at 9:56 AM, Roland King <email@hidden> wrote:

> Depends what you want to do with introspection. If you want to ensure a class responds to allObjects and you expect if it does it returns an NSArray, that still works in this case


It may work, but you're still calling private methods... :-/

Charles

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Not documented: NSArray responds to -allObjects (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Field editors behavior.
  • Next by Date: Spotlight importer don't work anymore under Mavericks (sandbox error)
  • Previous by thread: Re: OBJC_PRINT_REPLACED_METHODS logs a lot of noise?
  • Next by thread: NSTextField, maximum string length, bindings and NSFormatter
  • Index(es):
    • Date
    • Thread