Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare & implement an iOS method with blocks, but no other parameters

Need help declaring and implementing a method with blocks but no parameters. Sounds simple but I'm missing something because this works:

- (void) RetrieveDevices: (NSInteger)count
         success:(void (^)(NSMutableArray *devices))success
         failure:(void (^)(aylaError *err))failure;

- (void)RetrieveDevices:(NSInteger)count
        success:(void (^)(NSMutableArray *devices))successBlock
        failure:(void (^)(aylaError *err))failureBlock
{

}

And this won't compile as it's expecting a method body:

- (void) RetrieveDevices
             success:(void (^)(NSMutableArray *devices))success
             failure:(void (^)(aylaError *err))failure;

- (void)RetrieveDevices
            success:(void (^)(NSMutableArray *devices))successBlock
            failure:(void (^)(aylaError *err))failureBlock
{

}

Appreciate the help.

like image 610
Dan Avatar asked Jul 12 '12 22:07

Dan


People also ask

What is the meaning of declare?

declare verb (EXPRESS) B2 [ T ] to announce something clearly, firmly, publicly, or officially: They declared their support for the proposal. [ + (that) ] She declared (that) it was the best chocolate cake she had ever tasted. [ + obj + (to be) + noun/adj ] They declared themselves (to be) bankrupt.

What is a Declare label?

Declare is a nutrition label for building products. It is designed to help specifiers quickly identify products that meet their project requirements. Declare labels disclose all intentionally-added ingredients and residuals at or above 100ppm (0.01%) present in the final product by weight.

What is the verb for declaration?

declare verb (EXPRESS) B2 [ T ] to announce something clearly, firmly, publicly, or officially: They declared their support for the proposal

How does the verb declare differ from other words?

How does the verb declare differ from other similar words? Some common synonyms of declare are announce, proclaim, and promulgate. While all these words mean "to make known publicly," declare implies explicitness and usually formality in making known. Where would announce be a reasonable alternative to declare?


2 Answers

Blocks are parameters. So you want a method signature with two parameters. Try e.g.:

- (void) RetrieveDevicesWithSuccess:(void (^)(NSMutableArray *devices))success
                            failure:(void (^)(aylaError *err))failure;
like image 186
mikiancom Avatar answered Nov 15 '22 10:11

mikiancom


The problem is the newline and whitespace between "RetrieveDevices" and "success"/"failure". Try this instead:

- (void)RetrieveDevicesOnSuccess:(void (^)(NSMutableArray *devices))successBlock
                       onFailure:(void (^)(aylaError *err))failureBlock
{

}
like image 24
Andrew Madsen Avatar answered Nov 15 '22 08:11

Andrew Madsen