inference of block return type
inference of block return type
- Subject: inference of block return type
- From: Matt Neuburg <email@hidden>
- Date: Mon, 28 Jun 2010 09:51:37 -0700
- Thread-topic: inference of block return type
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.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
AppleScript: the Definitive Guide, 2nd edition
http://www.tidbits.com/matt/default.html#applescriptthings
Take Control of Exploring & Customizing Snow Leopard
http://tinyurl.com/kufyy8
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.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