I immerse myself in iOS programming, and I learn how to use blocks. I have a juicy, redesigned library that I use in my project and it uses one callback method to handle all data requests ...
@protocol SuckyClassDelegate <NSObject> -(void)returnedSuckyData:(NSMutableDictionary*)data; @end @interface SuckyClass: NSObject @property (nonatomic, weak) id<SuckyClassDelegate> delegate; -(void)getSuckyData; @end @interface MyViewController: UIViewController <SuckyClassDelegate> -(void)requestDataFromSuckyClass; @end
I would like to create a wrapper class for SuckyClass that allows me to use blocks when I need to access data from SuckyClass, but I don't know how to do it. I would like to have something like this ...
@interface SuckyClassWrapper - (void)requestDataWithSuccessBlock:(void(^)((NSMutableDictionary*)data))successBlock; @end @implementation MyViewController -(void)requestDataFromSuckyClass { SuckyClassWrapper *wrapper = [[SuckyClassWrapper alloc] init]; [wrapper requestDataWithSuccessBlock:^(NSMutableDictionary *data) { NSLog(@"%@", data); } } @end
... but I can't figure out how to convert the callback process to blocks. Can you somehow give me some direction here?
Thank you for your wisdom!
By the way, I just hacked the code without testing it, so I apologize if there are typos.
source share