• 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: blocks and id
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: blocks and id


  • Subject: Re: blocks and id
  • From: Uli Kusterer <email@hidden>
  • Date: Sat, 15 Dec 2012 01:38:37 +0100

On 12.12.2012, at 10:03, Andreas Grosam <email@hidden> wrote:
> How can I check at runtime whether an object (id) is actually a block, and not another kind of object?

 Not a good idea. What are you really trying to do? Here's a few common cases and suggestions on how to do it better, and why:

1) Serializing objects. Generally, the object (or a category on it if it's an object you didn't create) should implement a method that knows how to serialize/unserialize it, like -initWithCoder: and -encodeWithCoder:. This allows any class to be added, and allows for overriding a the method in a subclass. If you use -isKindOfClass:

2) Implementing special behaviour on some objects, while falling back on some default behaviour for all others. Call respondsToSelector: in this case. It has the advantage that it doesn't break duck typing. Even if you get an NSProxy for the actual object, it will respond to the selector and still work as expected.

Asking for an object's class using isKindOfClass: is a definite code smell.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.masters-of-the-void.com




_______________________________________________

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

  • Follow-Ups:
    • Re: blocks and id
      • From: Uli Kusterer <email@hidden>
References: 
 >blocks and id (From: Andreas Grosam <email@hidden>)

  • Prev by Date: Re: NSWorkspace recycleURLs:completionHandler error -5000 (afpAccessDenied)
  • Next by Date: Re: blocks and id
  • Previous by thread: Re: blocks and id
  • Next by thread: Re: blocks and id
  • Index(es):
    • Date
    • Thread