#import <Foundation/Foundation.h> @class TTOperation; @protocol TTOperationDelegate <NSObject> -(void)operationComplete:(NSData *)data; @end @interface TTOperation : NSOperation @property(nonatomic,weak)id<TTOperationDelegate>delegate; @end import "TTOperation.h" @implementation TTOperation //重写main方法 -(void)main { [super main]; NSData *firstData=[NSData dataWithContentsOfURL:[NSURL URLWithString:KURL1]]; dispatch_async(dispatch_get_main_queue(), ^{ if (_delegate&&[_delegate respondsToSelector:@selector(operationComplete:)]) { [_delegate operationComplete:firstData]; } }); } @end
时间: 2024-10-12 16:21:58