iPhone: Helpful Classes or extended Subclasses which should have been in the SDK

Posted by disp on Stack Overflow See other posts from Stack Overflow or by disp
Published on 2010-06-02T20:40:59Z Indexed on 2010/06/02 20:44 UTC
Read the original article Hit count: 242

Filed under:
|
|
|
|

This is more a community sharing post than a real question. In my iPhone OS projects I'm always importing a helper class with helpful methods which I can use for about every project.

So I thought it might be a good idea, if everyone shares some of their favorite methods, which should have been in everyones toolcase.

I'll start with an extension of the NSString class, so I can make strings with dates on the fly providing format and locale. Maybe someone can find some need in this.

   @implementation NSString (DateHelper)

+(NSString *) stringWithDate:(NSDate*)date withFormat:(NSString *)format withLocaleIdent:(NSString*)localeString{   
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];    
    //For example @"de-DE", or @"en-US"
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:localeString];  
    [dateFormatter setLocale:locale];

    // For example @"HH:mm"
    [dateFormatter setDateFormat:format];  

    NSString *string = [dateFormatter stringFromDate:date];

    [dateFormatter release];
    [locale release];

    return string;  
} 
@end

I'd love to see some of your tools.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about tools