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

I need help in declaring and implementing the method with blocks, but without parameters. It sounds simple, but something is missing for me because it 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 will not compile as it expects the body of the method:

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

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

}

Rate the help.

+5
source share
4 answers

Blocks are parameters. Therefore, you need a method signature with two parameters. Try for example:

- (void) RetrieveDevicesWithSuccess:(void (^)(NSMutableArray *devices))success
                            failure:(void (^)(aylaError *err))failure;
+12
source

The problem is a new line and a space between "RetrieveDevices" and "success" / "failure". Try instead:

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

}
+1
source

- :

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

, . :

- (RETURN_TYPE)method_name

:

- (RETURN_TYPE)method_name_part1:(PARAMETER_TYPE1)parameter1 name_part2:(PARAMETER_TYPE2)parameter2...

The first example has the correct syntax with the return type and three parameters, the second example has a space after the method name, so the compiler expects the body of the method (which it interprets as no parameter).

Also note that, by convention, method names begin with a lowercase letter.

0
source

All Articles