开发者

Objective-C Block which accepts an object and returns a boolean

开发者 https://www.devze.com 2023-01-12 23:09 出处:网络
Can you please write for me a block which conforms to this definition: (BOOL(^)(id))block. The closest I have gotten is:

Can you please write for me a block which conforms to this definition: (BOOL(^)(id))block.

The closest I have gotten is:

typedef BOOL (^birds)(MyObject*);
birds c = ^(MyObject* p){ return (BOO开发者_如何学运维L)[p.something boolValue]; };

But it seems passing this c in a message who wants (BOOL(^)(id))block is a no go.


if a Block BOOL (^block)(id) is expected you need to pass such a block and not a BOOL (^block)(MyObject *).

So try this:

typedef BOOL (^birds)(id);
birds c = ^(id pp) { MyObject *p = (MyObject *) pp; return [p.something boolValue]; };
0

精彩评论

暂无评论...
验证码 换一张
取 消