-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBCDebugUtilities.m
More file actions
109 lines (65 loc) · 2.37 KB
/
BCDebugUtilities.m
File metadata and controls
109 lines (65 loc) · 2.37 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// BCDebugUtilities.m
// Xynk
//
// Created by Tom Houpt on 14/8/4.
//
//
#import "BCDebugUtilities.h"
@implementation NotificationObject
-(id)initWithName:(NSString *)n andSender:(id)s; {
self = [super init];
if (self) {
_name = n;
_sender = s;
}
return self;
}
@end
@implementation NSNotificationCenter (DebuggingExtensions)
-(NSMutableArray *)notificationStack; { return notificationStack; }
-(void)setNotificationStack:(NSMutableArray *)ns; {
// ignore
}
NSMutableArray *notificationStack;
// keep a stack of how deep out notifications have gotten when debugging...
- (void)debugPostNotificationName:(NSString *)notificationName object:(id)notificationSender; {
#ifdef DEBUG
assert(false);
if (nil == notificationStack) {
notificationStack = [NSMutableArray array];
}
[notificationStack addObject: [[NotificationObject alloc] initWithName:notificationName andSender:notificationSender]];
NSLog(@"level: %ld notification: %@", [notificationStack count], notificationName);
#endif
[self postNotificationName:notificationName object:notificationSender];
#ifdef DEBUG
[notificationStack removeObject: [notificationStack lastObject]];
#endif
}
- (void)debugPostNotificationName:(NSString *)notificationName object:(id)notificationSender userInfo:(NSDictionary *)userInfo; {
#ifdef DEBUG
if (nil == notificationStack) {
notificationStack = [NSMutableArray array];
}
[notificationStack addObject: [[NotificationObject alloc] initWithName:notificationName andSender:notificationSender]];
NSLog(@"level: %ld notification: %@", [notificationStack count], notificationName);
assert(nil != userInfo);
assert(nil != [userInfo objectForKey:@"sender"]);
BOOL different_objects = true;
for (NotificationObject *note in notificationStack) {
different_objects = ([note sender] != [[notificationStack firstObject] sender]);
}
assert(1 >= [notificationStack count] || different_objects);
#endif
[self postNotificationName:notificationName object:notificationSender userInfo:userInfo];
#ifdef DEBUG
[notificationStack removeObject: [notificationStack lastObject]];
#endif
}
@end
#ifdef DEBUG
# define DebugLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DebugLog(...)
#endif