Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

NSOperation example

By: a guest on Aug 6th, 2011  |  syntax: Objective C  |  size: 1.59 KB  |  views: 287  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. //
  3. //  TumblrParseOperation.h
  4. //  Tumblr Media Manager
  5. //
  6. //  Created by Jose Luis Campaña Perez on 06/08/11.
  7. //  Copyright 2011 iZ3. All rights reserved.
  8. //  jose@iz3solutions.com
  9. //
  10.  
  11.  
  12. #import <Foundation/Foundation.h>
  13.  
  14. @protocol TumblrParseOperationDelegate
  15. -(void)tumblrParseFinishOperationWithData:(NSMutableArray *)data;
  16. @end
  17.  
  18.  
  19. @interface TumblrParseOperation : NSOperation
  20. {
  21.  
  22.     id <TumblrParseOperationDelegate> _delegate;
  23.     NSString *_jsonData;
  24.     NSMutableArray *_listaDatos;
  25.    
  26. }
  27.  
  28. @end
  29.  
  30.  
  31.  
  32. //
  33. //  TumblrParseOperation.m
  34. //  Tumblr Media Manager
  35. //
  36. //  Created by Jose Luis Campaña Perez on 06/08/11.
  37. //  Copyright 2011 iZ3. All rights reserved.
  38. //  jose@iz3solutions.com
  39. //
  40.  
  41. #import "TumblrParseOperation.h"
  42.  
  43. @implementation TumblrParseOperation
  44.  
  45. #pragma mark - INIT
  46.  
  47. - (id)initWithData:(NSString *)jsonData delegate:(id <TumblrParseOperationDelegate>)delegate
  48. {
  49.     self = [super init];
  50.     if (self != nil)
  51.     {
  52.         _jsonData = jsonData;
  53.         _delegate = delegate;
  54.         _listaDatos = [[NSMutableArray alloc] init];
  55.        
  56.     }
  57.     return self;
  58. }
  59.  
  60. - (void)dealloc
  61. {
  62.     [_jsonData release];
  63.     [_listaDatos release];
  64.    
  65.     [super dealloc];
  66. }
  67.  
  68.  
  69. -(void)main
  70. {
  71.     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  72.     [self parse];
  73.    
  74.     if (![self isCancelled])
  75.     {
  76.         // notify our AppDelegate that the parsing is complete
  77.         [_delegate tumblrParseFinishOperationWithData:_listaDatos];
  78.     }
  79.    
  80.     [pool release];
  81. }
  82.  
  83. -(void)parse
  84. {
  85.     //The hardjob        
  86. }
  87.    
  88.  
  89. @end