Reputation: 4080
I have an issue in Completion handler.
I have a method as below
-(void)authenticationRealmWithCompletion:(void (^)(AuthenticationRealm *authenticationRealm, NSError *error))completion realmId:(NSString *)realmId postDictionary:(NSDictionary *)postDictionary{
//my code
}
Now I declared a variable as below
typedef void(^completionHandler)(AuthenticationRealm *authenticationRealm, NSError *error);
Now I want to assign as below
-(void)authenticationRealmWithCompletion:(void (^)(AuthenticationRealm *authenticationRealm, NSError *error))completion realmId:(NSString *)realmId postDictionary:(NSDictionary *)postDictionary{
[completion copy];
//**HERE**..... Error Line
completionHandler(completion);
//my code
}
But I am getting error as Redefinition of 'completion'
Please suggest how to assign completion handler to another.
Upvotes: 0
Views: 624
Reputation: 3727
To assign completion handler you have to create property of completion handler.
@property (nonatomic, copy) completionHandler completion;
Then in your method assign using below code.
self.completion = completion;
Update
Method also be define as
-(void)authenticationRealmWithCompletion:(completionHandler)completion
realmId:(NSString *)realmId
postDictionary:(NSDictionary *)postDictionary{
self.completion = completion;
}
Upvotes: 3