Networking. h
# Import <Foundation/Foundation. h>
Typedef void (^ finishblock) (ID responseobject );
@ Interface networking: nsobject
@ Property (nonatomic, strong) finishblock;
+ (Void) getdatawithurl :( nsstring *) URL finshedblock :( finishblock) block;
@ End
Networking. m
# Import "networking. H"
# Import "afnetworking. H"
@ Implementation networking
+ (Void) getdatawithurl :( nsstring *) URL finshedblock :( finishblock) block
{
Networking * request = [[networking alloc] init];
Request. finishblock = block;
Afhttprequestoperationmanager * manager =
[Afhttprequestoperationmanager];
[Manager get: URL
Parameters: Nil
Success: ^ (afhttprequestoperation * operation, Id responseobject ){
If (request. finishblock ){
Request. finishblock (responseobject );
}
}
Failure: ^ (afhttprequestoperation * operation, nserror * error ){
Nslog (@ "error: % @", error );
}];
}
@ End
Encapsulate block request network data