This worked fine on the simulator, but CRASHED the iPhone. I had developed for a week simulator only, and was dismayed to find my iPhone not working.
After some digging I found a few posts on stack overflow that referenced using the -all_load flag, I tried that and it did not work. Then I noticed that I had another category that DID work, an expansion of set. The difference was that the expansion of NSSet did not have it's own files.
I then created a dummy class, and put all my categories into that class, after doing this my application worked fine, even though I didn't actually instantiate the class anywhere.
Sample include file (note in one case I included the category interface from another include, in the other I just cut & pasted it in:
//
// CategoryDummy.h
// JLFoundation
//
// Created by Jon Lundy on 3/23/10.
//
#import
#import "UIView_Helper.h"
#import "JLPredicateHelper_NSPredicate.h"
@interface UIView(AnimationHelper)
//
// Create a image of the current view, and give it a frame
// identical to the current location. The image view is autoreleased.
//
- (UIImageView *)createImageOfView;
@end
// A bug seems to cause categories to NOT work if they aren't in a file that
// is explicitly included.
@interface CategoryDummy : NSObject {
}
@end
And for the source file:
//
// CategoryDummy.m
// JLFoundation
//
// Created by Jon Lundy on 3/23/10.
//
#import "CategoryDummy.h"
#import
@implementation CategoryDummy
@end
@implementation NSPredicate(JLPredicateHelper)
+ (NSPredicate *) createSearchPredicate:(NSString*) fieldToSearchOn startingText:(NSString*) startingText
{
NSString *searchString=[startingText stringByAppendingString:@"*"];
NSString *predicateFormat=[[NSString alloc] initWithFormat:@"%@ like[cd] %%@",fieldToSearchOn];
NSPredicate *predicate=[NSPredicate predicateWithFormat:predicateFormat,searchString];
[predicateFormat release];
return predicate ;
}
@end
@implementation UIView(AnimationHelper)
//
// Create a image of the current view, and give it a frame
// identical to the current location. The image view is autoreleased.
//
- (UIImageView *)createImageOfView
{
// First getting a view of the current image.
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
// this function returns an autoreleased image.
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *imageView=[[UIImageView alloc] initWithImage :viewImage];
imageView.frame=self.frame;
return [imageView autorelease];
}
@end
Where JLPredicateHelper is:
Where JLPredicateHelper is:
//
// JLPredicateHelper_NSPredicate.h
// JLFoundation
//
// Created by Jon Lundy on 3/19/10.
@interface NSPredicate(JLPredicateHelper)
// This routine will create a predicate that searches a table on a certain field for any values
// that start with the same text (case insensitive). The predicate is returned autorelease.
+ (NSPredicate *) createSearchPredicate:(NSString*) fieldToSearchOn startingText:(NSString*) startingText;
@end
This was all I had to do to get my categories working on the iPhone. I was even able to remove the -all_load compiler flag.