/ Published in: Objective C
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
// -------------------------
// header file
// -------------------------
#ifndef RELEASE
#define PFValidateOutlets(obj) PFValidateOutlets_(obj, [NSString stringWithFormat:@"%s", __FILE__], nil)
#define PFValidateOutletsInFile(obj, header) PFValidateOutlets_(obj, [NSString stringWithFormat:@"%s", __FILE__], header)
#else
#define PFValidateOutlets(obj)
#define PFValidateOutletsInFile(obj, header)
#endif
// -------------------------
// .m file
// -------------------------
#import <objc/runtime.h>
{
#ifndef RELEASE
if (headerFilename) {
filepath = [[filepath stringByDeletingLastPathComponent] stringByAppendingPathComponent:headerFilename];
}
if (![filepath hasSuffix:@".h"]) {
}
// Parse the outlets
NSCharacterSet *wordTokenizingSet = [NSCharacterSet characterSetWithCharactersInString:@" \t\n\r{}*:;"];
NSCharacterSet *statementTokenizingSet = [NSCharacterSet characterSetWithCharactersInString:@"{}:;/"];
[scanner scanCharactersFromSet:spacesSet intoString:nil];
NSString *className;
// Proceed if the parsed class matches the object's class
if ([scanner scanUpToCharactersFromSet:wordTokenizingSet intoString:&className] &&
[className isEqualToString:NSStringFromClass([obj class])]) {
// Skip comment lines
if ([[line stringByTrimmingCharactersInSet:spacesSet] hasPrefix:@"//"]) continue;
if ([[statement stringByTrimmingCharactersInSet:spacesSet] hasPrefix:@"IBOutlet"]) {
NSString *outletName = [[statement componentsSeparatedByCharactersInSet:wordTokenizingSet] lastObject];
Ivar outletIvar = class_getInstanceVariable([obj class], [outletName UTF8String]);
id outletValue = object_getIvar(obj, outletIvar);
if (outletValue == nil)
NSLog(@"WARNING -- %@'s outlet %@ is nil", className, outletName, outletValue);
}
}
}
}
}
}
#endif
}
// -------------------------
// usage
// -------------------------
- (void)awakeFromNib
{
PFValidateOutlets(self);
// Rest of the code
}
URL: http://www.potionfactory.com/blog/2008/06/15/f-nil-outlets
Comments
 Subscribe to comments
                    Subscribe to comments
                
                