Global class iPhone with categories, is this correct?

advertisements

My singleton global class has all these categeories in same class, in header file their interfaces and in implemantation file their implementations as below,

This works, but I am not quite sure what I am doing is good practise here because it is a singleton class already and I am calling these methods as categories and doing some allocates, releases..and stuff. or they are alreday outside of the global class cause they are different implemantations?

Can you tell me if everything is correct here?

#import "GlobalConfig.h"
#import "SynthesizeSingleton.h"
@implementation GlobalConfig
SYNTHESIZE_SINGLETON_FOR_CLASS(GlobalConfig);
@end

@implementation UIColor (APP)
+(UIColor *) APP_NAV_COLOR { return [UIColor colorWithRed:00/256.0 green:111/256.0
                                                 blue:59/256.0 alpha:1.0]; }
+(UIColor *) APP_BUTTON_COLOR { return [UIColor colorWithRed:00/256.0 green:00/256.0
@end

@implementation UIImage(APP)
+(UIImage *) APP_IMAGE_BCKGROUND {

NSString *path = [[NSBundle mainBundle] pathForResource:@"bckPhone" ofType:@"png"];
return [UIImage imageWithContentsOfResolutionIndependentFile:path];
}
@end

@implementation CALayer(APP)
+(CALayer *) APP_SELECTION_VIEW:(UITableViewCell *)cell {
UIView *cellView = [[UIView alloc] initWithFrame:cell.frame];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = cellView.bounds;
gradient.startPoint = CGPointMake(0.5, 0);
gradient.endPoint = CGPointMake(0.5, 1);
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor APP_WHITE_COLOR] CGColor],    (id)[[UIColor APP_BLACK_COLOR] CGColor], nil];
[cellView release];
return gradient;
}
@end

@implementation UIView(APP)
+(UIView *) APP_BACKGROUND_VIEW:(UITableViewCell *)cell {
UIView *cellView2 = [[UIView alloc] initWithFrame:cell.frame];
CAGradientLayer *gradient2 = [CAGradientLayer layer];
gradient2.frame = cellView2.bounds;
gradient2.startPoint = CGPointMake(0, 0.5);
gradient2.endPoint = CGPointMake(1, 0.5);
gradient2.colors = [NSArray arrayWithObjects:(id)[[UIColor APP_WHITE_COLOR] CGColor], (id)[[UIColor APP_COLOR] CGColor], nil];
[cell.layer insertSublayer:gradient2 atIndex:0];
[cellView2 release];
UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];
 myBackView.backgroundColor=[[UIColor APP_COLOR] colorWithAlphaComponent:0.1];
[myBackView autorelease];
return myBackView;
}
@end


If you want to extend existing classes (i.e., CALayer, UIImage, and UIColor) through categories, you don't need a singleton.

A singleton is a class that you use to instantiate a single object (and have a guarantee at that is unique). A category is a way to extend an existing interface, without adding any ivars (only methods) and due to this you don't need to instantiate a category before using it. So categories and singletons responds to different requirements and there is no need to mix them.

You can simply define your categories like you do, and then use them with your UIView, UIColor and CALAyer objects.