the Reverend
the Reverend

Reputation: 12559

return a pointer to a block

I have a static block variable inside a class. How can I declare a property or an instance selector to return or send that block to a caller?

This is my static block:

static NSResultComparison(^myBlock)(id obj1, id obj2);

Upvotes: 1

Views: 1285

Answers (1)

Joe
Joe

Reputation: 57179

It would be best to typedef your block.

//interface.h
typedef NSResultComparison (^ComparisonBlock)(id obj1, id obj2);

@interface ...
...

-(ComparisonBlock) getComparisonBlock;

@end

//implementation.m
//Here is your static block implementation
static ComparisonBlock myStaticBlock = ^(id obj1, id obj2)
{
    ...
    return result;
};

@implementation ...

-(ComparisonBlock)getComparisonBlock
{
    return myStaticBlock;
}

@end

Upvotes: 5

Related Questions