/Classes/CallFuncWithObject.m

http://github.com/kstenerud/ObjectAL-for-iPhone · Objective C · 73 lines · 57 code · 10 blank · 6 comment · 5 complexity · 0e797c1d7709337a79d4df574498b8ed MD5 · raw file

  1. //
  2. // CallFuncWithObject.m
  3. // ObjectAL
  4. //
  5. // Created by Karl Stenerud.
  6. //
  7. #import "CallFuncWithObject.h"
  8. @implementation CallFuncWithObject
  9. + (id) actionWithTarget:(id)target
  10. selector:(SEL)selector
  11. object:(id) object
  12. {
  13. return [[[self alloc] initWithTarget:target selector:selector object:object] autorelease];
  14. }
  15. + (id) actionWithTarget:(id)target
  16. selector:(SEL)selector
  17. object:(id) object
  18. object:(id) object2
  19. {
  20. return [[[self alloc] initWithTarget:target selector:selector object:object object:object2] autorelease];
  21. }
  22. - (id) initWithTarget:(id)targetIn
  23. selector:(SEL)selectorIn
  24. object:(id) objectIn
  25. {
  26. if(nil != (self = [super initWithTarget:targetIn selector:selectorIn]))
  27. {
  28. object = [objectIn retain];
  29. twoObjects = NO;
  30. }
  31. return self;
  32. }
  33. - (id) initWithTarget:(id)targetIn
  34. selector:(SEL)selectorIn
  35. object:(id) objectIn
  36. object:(id) object2In
  37. {
  38. if(nil != (self = [super initWithTarget:targetIn selector:selectorIn]))
  39. {
  40. object = [objectIn retain];
  41. object2 = [object2In retain];
  42. twoObjects = YES;
  43. }
  44. return self;
  45. }
  46. - (void) dealloc
  47. {
  48. [object release];
  49. [object2 release];
  50. [super dealloc];
  51. }
  52. -(void) execute
  53. {
  54. if(twoObjects)
  55. {
  56. [targetCallback performSelector:selector withObject:object withObject:object2];
  57. }
  58. else
  59. {
  60. [targetCallback performSelector:selector withObject:object];
  61. }
  62. }
  63. @end