-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathNSObject+Extensions.m
60 lines (37 loc) · 1.57 KB
/
NSObject+Extensions.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
#import "NSObject+Extensions.h"
@implementation NSObject (Events)
/* Post Notification */
- (void) postNotificationAboutSelf: (id) name; {
[[NSNotificationCenter defaultCenter] postNotificationName: name object: self];
}
- (void) postNotificationAboutSelfLater: (id) name; {
[self performSelector: @selector(postNotificationAboutSelf:) withObject: name afterDelay: 0];
}
/* Listen For Notifications */
- (void) listenForNotification: (id) name selector: (SEL) sel; {
[[NSNotificationCenter defaultCenter] addObserver: self selector: sel name: name object: nil];
}
- (void) listenForNotification: (id) name selector: (SEL) sel object: (id) obj; {
[[NSNotificationCenter defaultCenter] addObserver: self selector: sel name: name object: obj];
}
/* Stop Listening For Notifications */
- (void) stopListening; {
[[NSNotificationCenter defaultCenter] removeObserver: self];
[NSObject cancelPreviousPerformRequestsWithTarget: self];
}
/* Timers */
- (id) repeatingTimerWithTimeInterval: (NSTimeInterval) interval selector: (SEL) sel; {
return [NSTimer scheduledTimerWithTimeInterval: interval target: self selector: sel userInfo: nil repeats: YES];
}
/* Guards */
- (void) kill; {
}
- (id) copyWithZone: (id) theZone; {
return [self retain];
}
@end
@implementation NSArray (Protection)
- (id) objectAtIndexA: (int) theIndex; {
return (theIndex > -1 && theIndex < [self count]) ? [self objectAtIndex: theIndex] : nil;
}
@end