-
Notifications
You must be signed in to change notification settings - Fork 0
/
CallBack.m
executable file
·68 lines (61 loc) · 1.31 KB
/
CallBack.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// ##############################################################
// CallBack.m
// Magic Number Machine
//
// Created by Matt Gallagher on Wed Apr 23 2003.
// Copyright (c) 2003 Matt Gallagher. All rights reserved.
// ##############################################################
#import "CallBack.h"
#import "NSObject+NSPerformSelector.h"
//
// About CallBack
//
// A small class which creates an object that sends the specified message when it
// is deleted. Useful to have an action called at Autorelease pool time.
//
@implementation CallBack
- (instancetype)init
{
self = [super init];
if (self) {
}
return self;
}
//
// initWithObject
//
// Constructor
//
- (instancetype)initWithObject:(id)object method:(CallBackType)method
{
self = [super init];
if (self)
{
callBackObject = object;
callBackMethod = method;
}
return self;
}
//
// dealloc
//
// The destructor is what calls the message
//
- (void)dealloc
{
// [NSObject target:callBackObject performSelector:callBackMethod];
if (callBackMethod) {
callBackMethod(nil);
}
// [callBackObject performSelector:callBackMethod];
}
//
// callBack
//
// Static method to create the object and autorelease it.
//
+ (instancetype)callBack:(id)object method:(CallBackType)method
{
return [[CallBack alloc] initWithObject:object method:method];
}
@end