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

Re: Use of blocks


  • Subject: Re: Use of blocks
  • From: Thomas Clement <email@hidden>
  • Date: Mon, 12 Jul 2010 16:11:36 +0200

On 12 juil. 2010, at 14:23, Giannandrea Castaldi wrote:

> On Mon, Jul 12, 2010 at 9:43 AM, vincent habchi <email@hidden> wrote:
>> Buongiorno :)
>>
>> Le 12 juil. 2010 à 09:34, Giannandrea Castaldi a écrit :
>>
>>> I want to use blocks to extract the min price and the max price from
>>> an NSArray of trips. I've found the following way:
>>>
>>>    float minValue = 0.0;
>>>    [someTrips enumerateObjectsUsingBlock:^(id obj, NSUInteger idx,
>>> BOOL *stop) {
>>>      if (minValue == 0.0 || [[obj adultFinalPrice] floatValue] < minValue) {
>>>        minValue = [obj floatValue];
>>>      }
>>>    }];
>>
>> […]
>>
>> Did you test it? Does it work? I've always heard that you could not modify block external variables unless you prefix them with __block. Otherwise the variable is just a const reference.
>>
>
> The snippet of code is simplified. In my project minValue and maxValue
> are object fields. In these fields I haven't used __block and my tests
> give me no error then it seems that for object fields __block doesn't
> need. Is it right?

Yes. Instance variables are modified via self.


Thomas

_______________________________________________

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: 
 >Use of blocks (From: Giannandrea Castaldi <email@hidden>)
 >Re: Use of blocks (From: vincent habchi <email@hidden>)
 >Re: Use of blocks (From: Giannandrea Castaldi <email@hidden>)

  • Prev by Date: Re: Use of blocks
  • Next by Date: getting/setting "check Grammar" in spellchecker panel, without NSTextView
  • Previous by thread: Re: Use of blocks
  • Next by thread: Re: Use of blocks
  • Index(es):
    • Date
    • Thread