In an Objective-C block, can you make the outer method return? a la Ruby proc? -
in ruby, calling return
inside block or nested blocks transfer control , return innermost wrapping method, i'm talking proc. in ruby lambda return
returns block , calling method continues, , how objective-c blocks work.
is there way ruby's proc semantics w.r.t returning in objective-c? want return inside block return outer method.
i'm not familiar ruby, way objc block exert control on enclosing method method test return value.
this simple as:
- (id)bloviate:(id (^)(void))bombast { // method returns results of block call; // thus, strictly speaking, method returns when // block does. return bombast(); }
or can check return value , conditionally return method:
- (id)elucidate:(bool (^)(id))explanation { id obj = /* object */; if( explanation(obj) ) { return obj; } // else continue }
Comments
Post a Comment