steipete / Aspects

Delightful, simple library for aspect oriented programming in Objective-C and Swift.
https://twitter.com/steipete
MIT License
8.4k stars 1.26k forks source link

How to method swizzling in asynchronous method?? #96

Closed KoonChaoSo closed 8 years ago

KoonChaoSo commented 8 years ago

[self.manager POST:path parameters:mapParams success:^(AFHTTPRequestOperation *operation, id responseObject) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { NSString *responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; NSDictionary *responseDic = [self p_JSONStringToNSDictionary:responseString]; NSInteger statusCode = [self statusCode:responseDic]; if(statusCode == 200) { if (success){ success(operation, responseDic); } } else { NSString *str = [responseDic objectForKey:@"message"]; if (str.length == 0) str = @"error"; NSError *error = [NSError errorWithDomain:str code:statusCode userInfo:nil]; fail(operation, error); } }); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { NSError *error = [NSError errorWithDomain:@"error" code:100001 userInfo:nil]; fail(operation, error); }); }];

How can i add some log using statusCode to success block with Aspects ?

steipete commented 8 years ago

You could wrap the block in your hook, but really not something where Aspects can help you much.

Please post questions like this on StackOverflow.

KoonChaoSo commented 8 years ago

Can Aspect wrap the block in my hook?

steipete commented 8 years ago

Yep.

PLease use StackOverflow for questions. It is very inconsiderate of you to ignore my previous comment.