Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: inference of block return type
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inference of block return type



Did you happen to read this link? It's clearly documented in the section Declaring and Using a Block. HTH.

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html

-Tony



On 6/28/10 9:51 AM, Matt Neuburg wrote:
I'm curious about the inference of a block literal's return type, but I'm
not sure what my question is. :) It all started with something like this
(reduced to a very very silly example, but it's the form that is important,
not the content):

[[NSArray array] indexesOfObjectsPassingTest:
     ^ (id object, NSUInteger idx, BOOL* stop) {
         return 1 == 1;
}]]; // compile error: ".... expected 'BOOL..."

My first problem was that I didn't know *how* to specify that this block
returns a BOOL. After much experimentation I discovered this syntax:

[[NSArray array] indexesOfObjectsPassingTest:
     ^ BOOL (id object, NSUInteger idx, BOOL* stop) {
         return 1 == 1;
}]];

I never expected the BOOL to come *after* the caret, and I can't find this
documented anywhere by Apple! Yet it does seem to silence the compiler, so I
must be doing something right.

Alternatively I can cast the result:

[[NSArray array] indexesOfObjectsPassingTest:
     ^ (id object, NSUInteger idx, BOOL* stop) {
         return (BOOL)(1 == 1);
}]];

As I say, I'm not sure what my question is, but I wondered if anyone had any
words of wisdom. And should I file a bug against the docs for failing to
tell me about the syntax in the second example? m.


_______________________________________________

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: 
 >inference of block return type (From: Matt Neuburg <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.