Skip to main content

Posts

NSURL of DocumentDirectory

- (NSURL *)applicationDocumentsDirectory {    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentPath = [searchPaths objectAtIndex:0];  // NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  // NSString *documentPath = [searchPaths lastObject];    return [NSURL fileURLWithPath:documentPath]; }

Remove All Images from Document Directory

-( void )removeImagesFromDocumentDic{     /* dir: the directory where your files are */     NSFileManager *fm = [ NSFileManager defaultManager ];     NSError *error = nil ;     NSString *docDirPath  =   [ NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory , NSUserDomainMask , YES ) objectAtIndex : 0 ];     NSArray *items = [fm contentsOfDirectoryAtPath :docDirPath error :&error];     if (error) { /* ... */ }          /* delete png files */     for ( NSString *item in items) {         if ([[item pathExtension ] isEqualToString : @"png" ]) {             NSString *path = [docDirPath stringByAppendingPathComponent :item];             [fm removeItemAtPath :path error :&error];             if (error)     ...

How to sort NSMutableArray using sortedArrayUsingDescriptors?

http://stackoverflow.com/questions/1844031/how-to-sort-nsmutablearray-using-sortedarrayusingdescriptors Example using NSString and NSNumber values with sorting on NSNumber value: NSString * NAME       = @ "name" ; NSString * ADDRESS   = @ "address" ; NSString * FREQUENCY = @ "frequency" ; NSString * TYPE       = @ "type" ; NSMutableArray * array = [ NSMutableArray array ]; NSDictionary * dict ; dict = [ NSDictionary dictionaryWithObjectsAndKeys :             @ "Alehandro" , NAME , @ "Sydney" , ADDRESS ,             [ NSNumber numberWithInt : 100 ], FREQUENCY ,             @ "T" , TYPE , nil ]; [ array addObject : dict ]; dict = [ NSDictionary dictionaryWithObjectsAndKeys :             @ "Xentro" , NAME , @ "Melbourne" , ADDRESS ,             [ NSNumb...

NSDateFormatter dateFromString and iPhone in 24 Hour Format Confusion

NSDate * date = [NSDate date];     NSLog ( @"datad %@" ,date)     NSDateFormatter * formatter = [[[NSDateFormatter alloc ] init ] autorelease ];     NSLocale   *enUSPOSIXLocale = [[[NSLocale alloc] initWithLocaleIdentifier : @"en_US_POSIX" ] autorelease];     [formatter setLocale :enUSPOSIXLocale];     [formatter setDateFormat : @"hh:mm a" ];     NSString * str = [formatter stringFromDate :date];     NSLog( @"str %@" ,str);

Set Local Notification

//Get Time from the UIDatePicker NSDate *selected = [[datePickerObj date] copy]; UILocalNotification *localNotification=[[UILocalNotification alloc]init];     localNotification.fireDate=[format dateFromString:[selected descriptionWithLocale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]];     [localNotification setFireDate:selected];     localNotification.alertBody=[NSString stringWithFormat:@"Time For The Prayer"];         /*      Options available for the repeat notification           NSEraCalendarUnit      NSYearCalendarUnit      NSMonthCalendarUnit      NSDayCalendarUnit      NSHourCalendarUnit      NSMinuteCalendarUnit      NSSecondCalendarUnit      NSWeekCalendarUnit ...