• 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: Jens Alfke <email@hidden>
  • Date: Wed, 12 Dec 2012 15:57:47 -0800

On Dec 12, 2012, at 5:24 AM, Andreas Grosam <email@hidden> wrote:

> And, it can be a block as well, where the block is responsible to feed the consumer (the id<RXMultipartFormdataPart>) with data when it has bytes available when the request is active.
> You can do this with the same method, same API. Well, it MUST, otherwise the number of combinations of the various types yielding different methods, would explode.


You don’t have to do it that way. An alternative is to make a class that can wrap any of those objects and remembers which one it is; then you can call [Parameter parameterWithString:] or +parameterWithNumber: or +parameterWithBlock: or whatever, and have methods on Parameter that can tell you what sort of object it was created with.

(NSValue has a very similar design — note that it can store a large number of different types without having to use a separate class for each one, or requiring the caller to use -isKindOfClass: to find out if a value is a point or a rect or a double.)

If you don’t want to do that, you should at least make a wrapper class around a block, like RXBlock. Basically just a simple class whose instances hold onto a block pointer. Then you can check whether a parameter is an instance of RXBlock, and if it is, get the block value from it. It’s only a bit more work for the client who has to call an RXBlock factory method instead of just passing in a block literal directly.

—Jens
_______________________________________________

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: 
 >blocks and id (From: Andreas Grosam <email@hidden>)
 >Re: blocks and id (From: Charles Srstka <email@hidden>)
 >Re: blocks and id (From: Andreas Grosam <email@hidden>)
 >Re: blocks and id (From: Mike Abdullah <email@hidden>)
 >Re: blocks and id (From: Andreas Grosam <email@hidden>)

  • Prev by Date: Re: blocks and id
  • Next by Date: Re: split views, best practices for 10.8?
  • Previous by thread: Re: blocks and id
  • Next by thread: Re: blocks and id
  • Index(es):
    • Date
    • Thread